use of com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException in project pulsar by yahoo.
the class PersistentTopic method unsubscribe.
/**
* Delete the cursor ledger for a given subscription
*
* @param subscriptionName
* Subscription for which the cursor ledger is to be deleted
* @return Completable future indicating completion of unsubscribe operation Completed exceptionally with:
* ManagedLedgerException if cursor ledger delete fails
*/
@Override
public CompletableFuture<Void> unsubscribe(String subscriptionName) {
CompletableFuture<Void> unsubscribeFuture = new CompletableFuture<>();
ledger.asyncDeleteCursor(Codec.encode(subscriptionName), new DeleteCursorCallback() {
@Override
public void deleteCursorComplete(Object ctx) {
if (log.isDebugEnabled()) {
log.debug("[{}][{}] Cursor deleted successfully", topic, subscriptionName);
}
subscriptions.remove(subscriptionName);
unsubscribeFuture.complete(null);
lastActive = System.nanoTime();
}
@Override
public void deleteCursorFailed(ManagedLedgerException exception, Object ctx) {
if (log.isDebugEnabled()) {
log.debug("[{}][{}] Error deleting cursor for subscription", topic, subscriptionName, exception);
}
unsubscribeFuture.completeExceptionally(new PersistenceException(exception));
}
}, null);
return unsubscribeFuture;
}
use of com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException in project pulsar by yahoo.
the class PersistentTopic method startReplicator.
CompletableFuture<Void> startReplicator(String remoteCluster) {
log.info("[{}] Starting replicator to remote: {}", topic, remoteCluster);
final CompletableFuture<Void> future = new CompletableFuture<>();
String name = PersistentReplicator.getReplicatorName(replicatorPrefix, remoteCluster);
ledger.asyncOpenCursor(name, new OpenCursorCallback() {
@Override
public void openCursorComplete(ManagedCursor cursor, Object ctx) {
String localCluster = brokerService.pulsar().getConfiguration().getClusterName();
replicators.computeIfAbsent(remoteCluster, r -> new PersistentReplicator(PersistentTopic.this, cursor, localCluster, remoteCluster, brokerService));
future.complete(null);
}
@Override
public void openCursorFailed(ManagedLedgerException exception, Object ctx) {
future.completeExceptionally(new PersistenceException(exception));
}
}, null);
return future;
}
use of com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException in project pulsar by yahoo.
the class PersistentSubscription method close.
/**
* Close the cursor ledger for this subscription. Requires that there are no active consumers on the dispatcher
*
* @return CompletableFuture indicating the completion of delete operation
*/
@Override
public CompletableFuture<Void> close() {
CompletableFuture<Void> closeFuture = new CompletableFuture<>();
synchronized (this) {
if (dispatcher != null && dispatcher.isConsumerConnected()) {
closeFuture.completeExceptionally(new SubscriptionBusyException("Subscription has active consumers"));
return closeFuture;
}
IS_FENCED_UPDATER.set(this, TRUE);
log.info("[{}][{}] Successfully fenced cursor ledger [{}]", topicName, subName, cursor);
}
cursor.asyncClose(new CloseCallback() {
@Override
public void closeComplete(Object ctx) {
if (log.isDebugEnabled()) {
log.debug("[{}][{}] Successfully closed cursor ledger", topicName, subName);
}
closeFuture.complete(null);
}
@Override
public void closeFailed(ManagedLedgerException exception, Object ctx) {
IS_FENCED_UPDATER.set(PersistentSubscription.this, FALSE);
log.error("[{}][{}] Error closing cursor for subscription", topicName, subName, exception);
closeFuture.completeExceptionally(new PersistenceException(exception));
}
}, null);
return closeFuture;
}
use of com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException in project pulsar by yahoo.
the class BrokerService method createPersistentTopic.
private CompletableFuture<Topic> createPersistentTopic(final String topic) throws RuntimeException {
checkTopicNsOwnership(topic);
final long topicCreateTimeMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
DestinationName destinationName = DestinationName.get(topic);
if (!pulsar.getNamespaceService().isServiceUnitActive(destinationName)) {
// namespace is being unloaded
String msg = String.format("Namespace is being unloaded, cannot add topic %s", topic);
log.warn(msg);
throw new RuntimeException(new ServiceUnitNotReadyException(msg));
}
final CompletableFuture<Topic> topicFuture = new CompletableFuture<>();
getManagedLedgerConfig(destinationName).thenAccept(config -> {
managedLedgerFactory.asyncOpen(destinationName.getPersistenceNamingEncoding(), config, new OpenLedgerCallback() {
@Override
public void openLedgerComplete(ManagedLedger ledger, Object ctx) {
PersistentTopic persistentTopic = new PersistentTopic(topic, ledger, BrokerService.this);
CompletableFuture<Void> replicationFuture = persistentTopic.checkReplication();
replicationFuture.thenRun(() -> {
log.info("Created topic {}", topic);
long topicLoadLatencyMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - topicCreateTimeMs;
pulsarStats.recordTopicLoadTimeValue(topic, topicLoadLatencyMs);
addTopicToStatsMaps(destinationName, persistentTopic);
topicFuture.complete(persistentTopic);
});
replicationFuture.exceptionally((ex) -> {
log.warn("Replication check failed. Removing topic from topics list {}, {}", topic, ex);
persistentTopic.stopReplProducers().whenComplete((v, exception) -> {
topics.remove(topic, topicFuture);
topicFuture.completeExceptionally(ex);
});
return null;
});
}
@Override
public void openLedgerFailed(ManagedLedgerException exception, Object ctx) {
log.warn("Failed to create topic {}", topic, exception);
topics.remove(topic, topicFuture);
topicFuture.completeExceptionally(new PersistenceException(exception));
}
}, null);
}).exceptionally((exception) -> {
log.warn("[{}] Failed to get topic configuration: {}", topic, exception.getMessage(), exception);
topics.remove(topic, topicFuture);
topicFuture.completeExceptionally(exception);
return null;
});
return topicFuture;
}
use of com.yahoo.pulsar.broker.service.BrokerServiceException.PersistenceException in project pulsar by yahoo.
the class PersistentTopic method addFailed.
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
PublishCallback callback = (PublishCallback) ctx;
log.error("[{}] Failed to persist msg in store: {}", topic, exception.getMessage());
callback.completed(new PersistenceException(exception), -1, -1);
if (exception instanceof ManagedLedgerFencedException) {
// If the managed ledger has been fenced, we cannot continue using it. We need to close and reopen
close();
}
}
Aggregations