use of org.apache.pulsar.metadata.api.GetResult in project pulsar by yahoo.
the class PulsarLedgerUnderreplicationManager method getCheckAllLedgersCTime.
@Override
public long getCheckAllLedgersCTime() throws ReplicationException.UnavailableException {
if (log.isDebugEnabled()) {
log.debug("setCheckAllLedgersCTime");
}
try {
Optional<GetResult> optRes = store.get(checkAllLedgersCtimePath).get();
if (!optRes.isPresent()) {
log.warn("checkAllLedgersCtimeZnode is not yet available");
return -1;
}
byte[] data = optRes.get().getValue();
CheckAllLedgersFormat checkAllLedgersFormat = CheckAllLedgersFormat.parseFrom(data);
return checkAllLedgersFormat.hasCheckAllLedgersCTime() ? checkAllLedgersFormat.getCheckAllLedgersCTime() : -1;
} catch (ExecutionException ee) {
throw new ReplicationException.UnavailableException("Error contacting zookeeper", ee);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new ReplicationException.UnavailableException("Interrupted while contacting zookeeper", ie);
} catch (InvalidProtocolBufferException ipbe) {
throw new ReplicationException.UnavailableException("Error while parsing ZK protobuf binary data", ipbe);
}
}
use of org.apache.pulsar.metadata.api.GetResult in project pulsar by yahoo.
the class PulsarLedgerUnderreplicationManager method getPlacementPolicyCheckCTime.
@Override
public long getPlacementPolicyCheckCTime() throws ReplicationException.UnavailableException {
if (log.isDebugEnabled()) {
log.debug("getPlacementPolicyCheckCTime");
}
try {
Optional<GetResult> optRes = store.get(placementPolicyCheckCtimePath).get();
if (!optRes.isPresent()) {
log.warn("placementPolicyCheckCtimeZnode is not yet available");
return -1;
}
byte[] data = optRes.get().getValue();
PlacementPolicyCheckFormat placementPolicyCheckFormat = PlacementPolicyCheckFormat.parseFrom(data);
return placementPolicyCheckFormat.hasPlacementPolicyCheckCTime() ? placementPolicyCheckFormat.getPlacementPolicyCheckCTime() : -1;
} catch (ExecutionException ee) {
throw new ReplicationException.UnavailableException("Error contacting zookeeper", ee);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new ReplicationException.UnavailableException("Interrupted while contacting zookeeper", ie);
} catch (InvalidProtocolBufferException ipbe) {
throw new ReplicationException.UnavailableException("Error while parsing ZK protobuf binary data", ipbe);
}
}
use of org.apache.pulsar.metadata.api.GetResult in project pulsar by yahoo.
the class PulsarRegistrationManager method readCookie.
@Override
public Versioned<byte[]> readCookie(BookieId bookieId) throws BookieException {
String path = this.cookiePath + "/" + bookieId;
try {
Optional<GetResult> res = store.get(path).get();
if (!res.isPresent()) {
throw new BookieException.CookieNotFoundException(bookieId.toString());
}
// sets stat version from MetadataStore
LongVersion version = new LongVersion(res.get().getStat().getVersion());
return new Versioned<>(res.get().getValue(), version);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new BookieException.MetadataStoreException(ie);
} catch (ExecutionException e) {
throw new BookieException.MetadataStoreException(e);
}
}
use of org.apache.pulsar.metadata.api.GetResult in project incubator-pulsar by apache.
the class NamespaceServiceTest method testUnloadNamespaceBundleFailure.
@Test
public void testUnloadNamespaceBundleFailure() throws Exception {
final String topicName = "persistent://my-property/use/my-ns/my-topic1";
pulsarClient.newConsumer().topic(topicName).subscriptionName("my-subscriber-name").subscribe();
ConcurrentOpenHashMap<String, CompletableFuture<Optional<Topic>>> topics = pulsar.getBrokerService().getTopics();
Topic spyTopic = spy(topics.get(topicName).get().get());
topics.clear();
CompletableFuture<Optional<Topic>> topicFuture = CompletableFuture.completedFuture(Optional.of(spyTopic));
// add mock topic
topics.put(topicName, topicFuture);
doAnswer((Answer<CompletableFuture<Void>>) invocation -> {
CompletableFuture<Void> result = new CompletableFuture<>();
result.completeExceptionally(new RuntimeException("first time failed"));
return result;
}).when(spyTopic).close(false);
NamespaceBundle bundle = pulsar.getNamespaceService().getBundle(TopicName.get(topicName));
pulsar.getNamespaceService().unloadNamespaceBundle(bundle).join();
Optional<GetResult> res = this.pulsar.getLocalMetadataStore().get(ServiceUnitUtils.path(bundle)).join();
assertFalse(res.isPresent());
}
use of org.apache.pulsar.metadata.api.GetResult in project incubator-pulsar by apache.
the class MetadataStoreTest method insertionTestWithExpectedVersion.
@Test(dataProvider = "impl")
public void insertionTestWithExpectedVersion(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
String key1 = newKey();
try {
store.put(key1, "value-1".getBytes(), Optional.of(0L)).join();
fail("Should have failed");
} catch (CompletionException e) {
assertException(e, BadVersionException.class);
}
try {
store.put(key1, "value-1".getBytes(), Optional.of(1L)).join();
fail("Should have failed");
} catch (CompletionException e) {
assertException(e, BadVersionException.class);
}
store.put(key1, "value-1".getBytes(), Optional.of(-1L)).join();
assertTrue(store.exists(key1).join());
Optional<GetResult> optRes = store.get(key1).join();
assertTrue(optRes.isPresent());
assertEquals(optRes.get().getValue(), "value-1".getBytes());
assertEquals(optRes.get().getStat().getVersion(), 0);
try {
store.put(key1, "value-2".getBytes(), Optional.of(-1L)).join();
fail("Should have failed");
} catch (CompletionException e) {
assertException(e, BadVersionException.class);
}
try {
store.put(key1, "value-2".getBytes(), Optional.of(1L)).join();
fail("Should have failed");
} catch (CompletionException e) {
assertException(e, BadVersionException.class);
}
assertTrue(store.exists(key1).join());
optRes = store.get(key1).join();
assertTrue(optRes.isPresent());
assertEquals(optRes.get().getValue(), "value-1".getBytes());
assertEquals(optRes.get().getStat().getVersion(), 0);
store.put(key1, "value-2".getBytes(), Optional.of(0L)).join();
assertTrue(store.exists(key1).join());
optRes = store.get(key1).join();
assertTrue(optRes.isPresent());
assertEquals(optRes.get().getValue(), "value-2".getBytes());
assertEquals(optRes.get().getStat().getVersion(), 1);
}
Aggregations