use of io.pravega.client.tables.impl.TableSegmentEntry in project pravega by pravega.
the class SegmentHelper method readTable.
public CompletableFuture<List<TableSegmentEntry>> readTable(final String tableName, final PravegaNodeUri uri, final List<TableSegmentKey> keys, String delegationToken, final long clientRequestId) {
final WireCommandType type = WireCommandType.READ_TABLE;
// the version is always NO_VERSION as read returns the latest version of value.
List<WireCommands.TableKey> keyList = keys.stream().map(k -> new WireCommands.TableKey(k.getKey(), k.getVersion().getSegmentVersion())).collect(Collectors.toList());
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.ReadTable request = new WireCommands.ReadTable(requestId, tableName, delegationToken, keyList);
return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTable.class, type);
return ((WireCommands.TableRead) rpl).getEntries().getEntries().stream().map(this::convertFromWireCommand).collect(Collectors.toList());
});
}
use of io.pravega.client.tables.impl.TableSegmentEntry in project pravega by pravega.
the class PravegaTablesScopeTest method testRemoveTagsUnderScope.
@Test(timeout = 5000)
@SuppressWarnings("unchecked")
public void testRemoveTagsUnderScope() {
// Setup Mocks.
GrpcAuthHelper authHelper = mock(GrpcAuthHelper.class);
when(authHelper.retrieveMasterToken()).thenReturn("");
SegmentHelper segmentHelper = mock(SegmentHelper.class);
PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executorService());
PravegaTablesScope tablesScope = spy(new PravegaTablesScope(scope, storeHelper));
doReturn(CompletableFuture.completedFuture(indexTable)).when(tablesScope).getAllStreamTagsInScopeTableNames(stream, context);
// Simulate an empty value being returned.
TableSegmentEntry entry = TableSegmentEntry.versioned(tagBytes, new byte[0], 1L);
when(segmentHelper.readTable(eq(indexTable), any(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(singletonList(entry)));
when(segmentHelper.updateTableEntries(eq(indexTable), any(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(singletonList(TableSegmentKeyVersion.from(2L))));
when(segmentHelper.removeTableKeys(eq(indexTable), any(), anyString(), anyLong())).thenAnswer(invocation -> {
// Capture the key value sent during removeTableKeys.
keySnapshot = (List<TableSegmentKey>) invocation.getArguments()[1];
return CompletableFuture.completedFuture(null);
});
// Invoke the removeTags method.
tablesScope.removeTagsUnderScope(stream, Set.of(tag), context).join();
// Verify if correctly detect that the data is empty and the entry is cleaned up.
verify(segmentHelper, times(1)).removeTableKeys(eq(indexTable), eq(keySnapshot), anyString(), anyLong());
// Verify if the version number is as expected.
assertEquals(2L, keySnapshot.get(0).getVersion().getSegmentVersion());
}
use of io.pravega.client.tables.impl.TableSegmentEntry in project pravega by pravega.
the class ControllerMetadataCommand method getTableEntry.
/**
* Method to get the entry corresponding to the provided key in the table.
*
* @param tableName The name of the table.
* @param key The key.
* @param segmentStoreHost The address of the segment store instance.
* @param adminSegmentHelper An instance of {@link AdminSegmentHelper}.
* @return The queried table segment entry.
*/
TableSegmentEntry getTableEntry(String tableName, String key, String segmentStoreHost, AdminSegmentHelper adminSegmentHelper) {
ByteArraySegment serializedKey = new ByteArraySegment(KEY_SERIALIZER.serialize(key));
List<TableSegmentEntry> entryList = completeSafely(adminSegmentHelper.readTable(tableName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), Collections.singletonList(TableSegmentKey.unversioned(serializedKey.getCopy())), authHelper.retrieveMasterToken(), 0L), tableName, key);
if (entryList == null) {
return null;
}
if (entryList.get(0).getKey().getVersion().equals(TableSegmentKeyVersion.NOT_EXISTS)) {
output(String.format("Key not found: %s", key));
return null;
}
return entryList.get(0);
}
use of io.pravega.client.tables.impl.TableSegmentEntry in project pravega by pravega.
the class ControllerMetadataCommand method updateTableEntry.
/**
* Method to update entry corresponding to the provided key in the table.
*
* @param tableName The name of the table.
* @param key The key.
* @param value The new value.
* @param version The expected update version.
* @param segmentStoreHost The address of the segment store instance.
* @param adminSegmentHelper An instance of {@link AdminSegmentHelper}.
* @return The new key version after the update takes place successfully.
*/
TableSegmentKeyVersion updateTableEntry(String tableName, String key, ByteBuffer value, long version, String segmentStoreHost, AdminSegmentHelper adminSegmentHelper) {
ByteArraySegment serializedKey = new ByteArraySegment(KEY_SERIALIZER.serialize(key));
ByteArraySegment serializedValue = new ByteArraySegment(value);
TableSegmentEntry updatedEntry = TableSegmentEntry.versioned(serializedKey.getCopy(), serializedValue.getCopy(), version);
List<TableSegmentKeyVersion> keyVersions = completeSafely(adminSegmentHelper.updateTableEntries(tableName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), Collections.singletonList(updatedEntry), authHelper.retrieveMasterToken(), 0L), tableName, key);
if (keyVersions == null) {
return null;
}
return keyVersions.get(0);
}
use of io.pravega.client.tables.impl.TableSegmentEntry in project pravega by pravega.
the class TableSegmentCommand method updateTableEntry.
/**
* Method to update the entry corresponding to the provided key in the table segment.
*
* @param tableSegmentName The name of the table segment.
* @param key The key.
* @param value The entry to be updated in the table segment.
* @param segmentStoreHost The address of the segment store instance.
* @param adminSegmentHelper An instance of {@link AdminSegmentHelper}
* @return A long indicating the version obtained from updating the provided key in the table segment.
*/
long updateTableEntry(String tableSegmentName, String key, String value, String segmentStoreHost, AdminSegmentHelper adminSegmentHelper) {
ByteArraySegment serializedKey = new ByteArraySegment(getCommandArgs().getState().getKeySerializer().serialize(key));
ByteArraySegment serializedValue = new ByteArraySegment(getCommandArgs().getState().getValueSerializer().serialize(value));
TableSegmentEntry updatedEntry = TableSegmentEntry.unversioned(serializedKey.getCopy(), serializedValue.getCopy());
CompletableFuture<List<TableSegmentKeyVersion>> reply = adminSegmentHelper.updateTableEntries(tableSegmentName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), Collections.singletonList(updatedEntry), super.authHelper.retrieveMasterToken(), 0L);
return reply.join().get(0).getSegmentVersion();
}
Aggregations