use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project pulsar by apache.
the class PersistentTopic method triggerOffload.
public synchronized void triggerOffload(MessageIdImpl messageId) throws AlreadyRunningException {
if (currentOffload.isDone()) {
CompletableFuture<MessageIdImpl> promise = currentOffload = new CompletableFuture<>();
log.info("[{}] Starting offload operation at messageId {}", topic, messageId);
getManagedLedger().asyncOffloadPrefix(PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId()), new OffloadCallback() {
@Override
public void offloadComplete(Position pos, Object ctx) {
PositionImpl impl = (PositionImpl) pos;
log.info("[{}] Completed successfully offload operation at messageId {}", topic, messageId);
promise.complete(new MessageIdImpl(impl.getLedgerId(), impl.getEntryId(), -1));
}
@Override
public void offloadFailed(ManagedLedgerException exception, Object ctx) {
log.warn("[{}] Failed offload operation at messageId {}", topic, messageId, exception);
promise.completeExceptionally(exception);
}
}, null);
} else {
throw new AlreadyRunningException("Offload already in progress");
}
}
use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project pulsar by yahoo.
the class PersistentTopicsBase method internalTriggerCompactionNonPartitionedTopic.
protected void internalTriggerCompactionNonPartitionedTopic(AsyncResponse asyncResponse, boolean authoritative) {
validateTopicOwnershipAsync(topicName, authoritative).thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.COMPACT)).thenCompose(__ -> getTopicReferenceAsync(topicName)).thenAccept(topic -> {
try {
((PersistentTopic) topic).triggerCompaction();
asyncResponse.resume(Response.noContent().build());
} catch (AlreadyRunningException e) {
resumeAsyncResponseExceptionally(asyncResponse, new RestException(Status.CONFLICT, e.getMessage()));
return;
} catch (Exception e) {
log.error("[{}] Failed to trigger compaction on topic {}", clientAppId(), topicName, e);
resumeAsyncResponseExceptionally(asyncResponse, new RestException(e));
return;
}
}).exceptionally(ex -> {
// If the exception is not redirect exception we need to log it.
if (!isRedirectException(ex)) {
log.error("[{}] Failed to trigger compaction for {}", clientAppId(), topicName, ex);
}
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}
use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project incubator-pulsar by apache.
the class PersistentTopicsBase method internalTriggerCompactionNonPartitionedTopic.
protected void internalTriggerCompactionNonPartitionedTopic(AsyncResponse asyncResponse, boolean authoritative) {
validateTopicOwnershipAsync(topicName, authoritative).thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.COMPACT)).thenCompose(__ -> getTopicReferenceAsync(topicName)).thenAccept(topic -> {
try {
((PersistentTopic) topic).triggerCompaction();
asyncResponse.resume(Response.noContent().build());
} catch (AlreadyRunningException e) {
resumeAsyncResponseExceptionally(asyncResponse, new RestException(Status.CONFLICT, e.getMessage()));
return;
} catch (Exception e) {
log.error("[{}] Failed to trigger compaction on topic {}", clientAppId(), topicName, e);
resumeAsyncResponseExceptionally(asyncResponse, new RestException(e));
return;
}
}).exceptionally(ex -> {
// If the exception is not redirect exception we need to log it.
if (!isRedirectException(ex)) {
log.error("[{}] Failed to trigger compaction for {}", clientAppId(), topicName, ex);
}
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}
use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project incubator-pulsar by apache.
the class PersistentTopicsBase method internalTriggerOffload.
protected void internalTriggerOffload(AsyncResponse asyncResponse, boolean authoritative, MessageIdImpl messageId) {
validateTopicOwnershipAsync(topicName, authoritative).thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.OFFLOAD)).thenCompose(__ -> getTopicReferenceAsync(topicName)).thenAccept(topic -> {
try {
((PersistentTopic) topic).triggerOffload(messageId);
asyncResponse.resume(Response.noContent().build());
} catch (AlreadyRunningException e) {
resumeAsyncResponseExceptionally(asyncResponse, new RestException(Status.CONFLICT, e.getMessage()));
return;
} catch (Exception e) {
log.warn("Unexpected error triggering offload", e);
resumeAsyncResponseExceptionally(asyncResponse, new RestException(e));
return;
}
}).exceptionally(ex -> {
// If the exception is not redirect exception we need to log it.
if (!isRedirectException(ex)) {
log.error("[{}] Failed to trigger offload for {}", clientAppId(), topicName, ex);
}
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}
use of org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException in project incubator-pulsar by apache.
the class PersistentTopic method triggerOffload.
public synchronized void triggerOffload(MessageIdImpl messageId) throws AlreadyRunningException {
if (currentOffload.isDone()) {
CompletableFuture<MessageIdImpl> promise = currentOffload = new CompletableFuture<>();
log.info("[{}] Starting offload operation at messageId {}", topic, messageId);
getManagedLedger().asyncOffloadPrefix(PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId()), new OffloadCallback() {
@Override
public void offloadComplete(Position pos, Object ctx) {
PositionImpl impl = (PositionImpl) pos;
log.info("[{}] Completed successfully offload operation at messageId {}", topic, messageId);
promise.complete(new MessageIdImpl(impl.getLedgerId(), impl.getEntryId(), -1));
}
@Override
public void offloadFailed(ManagedLedgerException exception, Object ctx) {
log.warn("[{}] Failed offload operation at messageId {}", topic, messageId, exception);
promise.completeExceptionally(exception);
}
}, null);
} else {
throw new AlreadyRunningException("Offload already in progress");
}
}
Aggregations