Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.pulsar.metadata.api.GetResult;
import org.apache.pulsar.metadata.api.MetadataStoreConfig;
import org.apache.pulsar.metadata.api.MetadataStoreException;
import org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException;
import org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException;
import org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException;
import org.apache.pulsar.metadata.api.Notification;
Expand Down Expand Up @@ -130,7 +131,7 @@ public synchronized CompletableFuture<Stat> storePut(String path, byte[] data, O
Value newValue = new Value(0, data, now, now);
Value existingValue = map.putIfAbsent(path, newValue);
if (existingValue != null) {
return FutureUtils.exception(new BadVersionException(""));
return FutureUtils.exception(new AlreadyExistsException(""));
} else {
receivedNotification(new Notification(NotificationType.Created, path));
String parent = parent(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.pulsar.metadata.api.GetResult;
import org.apache.pulsar.metadata.api.MetadataStoreConfig;
import org.apache.pulsar.metadata.api.MetadataStoreException;
import org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException;
import org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException;
import org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException;
import org.apache.pulsar.metadata.api.Notification;
Expand Down Expand Up @@ -213,7 +214,7 @@ public CompletableFuture<Stat> storePut(String path, byte[] value, Optional<Long
future.complete(new Stat(name, 0, 0, 0));
} else if (code == Code.NODEEXISTS) {
// We're emulating a request to create node, so the version is invalid
future.completeExceptionally(getException(Code.BADVERSION, path));
future.completeExceptionally(getException(Code.NODEEXISTS, path));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done on purpose here. Since there is no "create()" operation but just the put() with the optional expected version. A create() is equivalent to a put(Optional.of(-1)) (eg: expecting the node not to be there). In that light it makes sense to me to stick to the BadVersion.

If the caller wants to make sure to create an entry, it just need to treat the bad version error for what it is: the state it's not what was expected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can handle BADVERSION as NODEEXISTS at caller side. but my only concern was what exact benefit we can get by returning different error-code. because actual error (in this case AlreadyExist) can help better in handling failure rather than deriving from BADVERSION . I will try to change handling at caller side but I think we might have usecases in future to explicitly know specific error to handle the failure.

} else {
future.completeExceptionally(getException(code, path));
}
Expand Down Expand Up @@ -296,6 +297,8 @@ private static MetadataStoreException getException(Code code, String path) {
return new BadVersionException(ex);
case NONODE:
return new NotFoundException(ex);
case NODEEXISTS:
return new AlreadyExistsException(ex);
default:
return new MetadataStoreException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.pulsar.metadata.api.MetadataStore;
import org.apache.pulsar.metadata.api.MetadataStoreConfig;
import org.apache.pulsar.metadata.api.MetadataStoreException;
import org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException;
import org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException;
import org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException;
import org.apache.pulsar.metadata.api.MetadataStoreFactory;
Expand Down Expand Up @@ -110,7 +111,7 @@ public void insertionTestWithExpectedVersion(String provider, String url) throws
store.put(key1, "value-2".getBytes(), Optional.of(-1L)).join();
fail("Should have failed");
} catch (CompletionException e) {
assertException(e, BadVersionException.class);
assertException(e, AlreadyExistsException.class);
}

try {
Expand Down