use of co.cask.cdap.messaging.TopicMetadata in project cdap by caskdata.
the class HBaseTableCoprocessorTestRun method testInvalidTx.
@Test
public void testInvalidTx() throws Exception {
try (MetadataTable metadataTable = getMetadataTable();
MessageTable messageTable = getMessageTable()) {
TopicId topicId = NamespaceId.DEFAULT.topic("invalidTx");
TopicMetadata topic = new TopicMetadata(topicId, TopicMetadata.TTL_KEY, "1000000", TopicMetadata.GENERATION_KEY, Integer.toString(GENERATION));
metadataTable.createTopic(topic);
List<MessageTable.Entry> entries = new ArrayList<>();
long invalidTxWritePtr = invalidSet.get(0);
entries.add(new TestMessageEntry(topicId, GENERATION, "data", invalidTxWritePtr, (short) 0));
messageTable.store(entries.iterator());
// Fetch the entries and make sure we are able to read it
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, null)) {
checkEntry(iterator, invalidTxWritePtr);
}
// Fetch the entries with tx and make sure we are able to read it
Transaction tx = new Transaction(V[8], V[8], new long[0], new long[0], -1);
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, tx)) {
checkEntry(iterator, invalidTxWritePtr);
}
// Now run full compaction
forceFlushAndCompact(Table.MESSAGE);
// Try to fetch the entry non-transactionally and the entry should still be there
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, null)) {
checkEntry(iterator, invalidTxWritePtr);
}
// Fetch the entries transactionally and we should see no entries returned
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, tx)) {
Assert.assertFalse(iterator.hasNext());
}
metadataTable.deleteTopic(topicId);
// Sleep so that the metadata cache expires
TimeUnit.SECONDS.sleep(3 * METADATA_CACHE_EXPIRY);
forceFlushAndCompact(Table.MESSAGE);
// Test deletion of messages from a deleted topic
try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, null)) {
Assert.assertFalse(iterator.hasNext());
}
}
}
use of co.cask.cdap.messaging.TopicMetadata in project cdap by caskdata.
the class CoreMessagingService method createTopic.
@Override
public void createTopic(TopicMetadata topicMetadata) throws TopicAlreadyExistsException, IOException {
try (MetadataTable metadataTable = createMetadataTable()) {
Map<String, String> properties = createDefaultProperties();
properties.putAll(topicMetadata.getProperties());
metadataTable.createTopic(new TopicMetadata(topicMetadata.getTopicId(), properties, true));
}
}
use of co.cask.cdap.messaging.TopicMetadata in project cdap by caskdata.
the class CoreMessagingService method rollback.
@Override
public void rollback(TopicId topicId, RollbackDetail rollbackDetail) throws TopicNotFoundException, IOException {
TopicMetadata metadata = getTopic(topicId);
Exception failure = null;
try (MessageTable messageTable = createMessageTable(metadata)) {
messageTable.rollback(metadata, rollbackDetail);
} catch (Exception e) {
failure = e;
}
// Throw if there is any failure in rollback.
if (failure != null) {
Throwables.propagateIfPossible(failure, TopicNotFoundException.class, IOException.class);
throw Throwables.propagate(failure);
}
}
use of co.cask.cdap.messaging.TopicMetadata in project cdap by caskdata.
the class MetadataHandler method getTopic.
@GET
@Path("/topics/{topic}")
public void getTopic(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception {
TopicId topicId = new NamespaceId(namespace).topic(topic);
TopicMetadata metadata = messagingService.getTopic(topicId);
responder.sendJson(HttpResponseStatus.OK, metadata.getProperties(), TOPIC_PROPERTY_TYPE);
}
use of co.cask.cdap.messaging.TopicMetadata in project cdap by caskdata.
the class CoreMessagingService method storePayload.
@Override
public void storePayload(StoreRequest request) throws TopicNotFoundException, IOException {
try {
TopicMetadata metadata = topicCache.get(request.getTopicId());
payloadTableWriterCache.get(request.getTopicId()).persist(request, metadata);
} catch (ExecutionException e) {
Throwable cause = Objects.firstNonNull(e.getCause(), e);
Throwables.propagateIfPossible(cause, TopicNotFoundException.class, IOException.class);
throw Throwables.propagate(e);
}
}
Aggregations