use of herddb.log.LogSequenceNumber in project herddb by diennea.
the class SimpleCDCTest method testBasicCaptureDataChangeWithRestart.
@Test
public void testBasicCaptureDataChangeWithRestart() throws Exception {
ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
ClientConfiguration client_configuration = new ClientConfiguration(folder.newFolder().toPath());
client_configuration.set(ClientConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
client_configuration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
client_configuration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
client_configuration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).column("d", ColumnTypes.INTEGER).primaryKey("c").build();
server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 1, "d", 2)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 2, "d", 2)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 3, "d", 2)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 4, "d", 2)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
InMemoryTableHistoryStorage tableHistoryStorage = new InMemoryTableHistoryStorage();
LogSequenceNumber currentPosition = LogSequenceNumber.START_OF_TIME;
List<ChangeDataCapture.Mutation> mutations = new ArrayList<>();
currentPosition = performOneCDCStep(client_configuration, server_1, tableHistoryStorage, currentPosition, mutations);
// we are missing the last entry, because it is not confirmed yet on BookKeeper at this point
assertEquals(4, mutations.size());
server_1.getManager().executeUpdate(new UpdateStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 4, "d", 2), null), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
currentPosition = performOneCDCStep(client_configuration, server_1, tableHistoryStorage, currentPosition, mutations);
assertEquals(5, mutations.size());
server_1.getManager().executeStatement(new AlterTableStatement(Arrays.asList(Column.column("e", ColumnTypes.INTEGER)), Collections.emptyList(), Collections.emptyList(), null, table.name, TableSpace.DEFAULT, null, Collections.emptyList(), Collections.emptyList()), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
currentPosition = performOneCDCStep(client_configuration, server_1, tableHistoryStorage, currentPosition, mutations);
assertEquals(6, mutations.size());
server_1.getManager().executeUpdate(new DeleteStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(1), null), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
currentPosition = performOneCDCStep(client_configuration, server_1, tableHistoryStorage, currentPosition, mutations);
assertEquals(7, mutations.size());
// close the server...close the ledger, now we can read the last mutation
server_1.close();
currentPosition = performOneCDCStep(client_configuration, server_1, tableHistoryStorage, currentPosition, mutations);
assertEquals(8, mutations.size());
int i = 0;
assertEquals(ChangeDataCapture.MutationType.CREATE_TABLE, mutations.get(i++).getMutationType());
assertEquals(ChangeDataCapture.MutationType.INSERT, mutations.get(i++).getMutationType());
assertEquals(ChangeDataCapture.MutationType.INSERT, mutations.get(i++).getMutationType());
assertEquals(ChangeDataCapture.MutationType.INSERT, mutations.get(i++).getMutationType());
assertEquals(ChangeDataCapture.MutationType.INSERT, mutations.get(i++).getMutationType());
assertEquals(ChangeDataCapture.MutationType.UPDATE, mutations.get(i++).getMutationType());
assertEquals(ChangeDataCapture.MutationType.ALTER_TABLE, mutations.get(i++).getMutationType());
assertEquals(ChangeDataCapture.MutationType.DELETE, mutations.get(i++).getMutationType());
}
}
use of herddb.log.LogSequenceNumber in project herddb by diennea.
the class TableStatus method deserialize.
public static TableStatus deserialize(ExtendedDataInputStream in) throws IOException {
// version
long version = in.readVLong();
// flags for future implementations
long flags = in.readVLong();
if (version != 1 || flags != 0) {
throw new DataStorageManagerException("corrupted table status");
}
String tableName = in.readUTF();
long ledgerId = in.readLong();
long offset = in.readLong();
long nextPageId = in.readLong();
byte[] nextPrimaryKeyValue = in.readArray();
int numActivePages = in.readVInt();
Map<Long, DataPageMetaData> activePages = new HashMap<>(numActivePages);
for (int i = 0; i < numActivePages; i++) {
activePages.put(in.readVLong(), DataPageMetaData.deserialize(in));
}
return new TableStatus(tableName, new LogSequenceNumber(ledgerId, offset), nextPrimaryKeyValue, nextPageId, activePages);
}
use of herddb.log.LogSequenceNumber in project herddb by diennea.
the class BootAsNewLeaderTest method testLeaderOnlineLogNoMoreAvailableDataAlreadyPresentBootAsNewLeader.
@Test
public void testLeaderOnlineLogNoMoreAvailableDataAlreadyPresentBootAsNewLeader() throws Exception {
final AtomicInteger countErase = new AtomicInteger();
SystemInstrumentation.addListener(new SystemInstrumentation.SingleInstrumentationPointListener("eraseTablespaceData") {
@Override
public void acceptSingle(Object... args) throws Exception {
countErase.incrementAndGet();
}
});
ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
serverconfig_1.set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_LEDGERS_RETENTION_PERIOD, 1);
serverconfig_1.set(ServerConfiguration.PROPERTY_CHECKPOINT_PERIOD, 0);
// disabled
serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_MAX_IDLE_TIME, 0);
ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath());
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).column("s", ColumnTypes.INTEGER).primaryKey("c").build();
Index index = Index.builder().onTable(table).type(Index.TYPE_BRIN).column("s", ColumnTypes.STRING).build();
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeStatement(new CreateIndexStatement(index), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 1, "s", "1")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 2, "s", "2")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 3, "s", "3")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 4, "s", "4")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server1", 1, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
TranslatedQuery translated = server_1.getManager().getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM " + TableSpace.DEFAULT + ".t1 WHERE s=1", Collections.emptyList(), true, true, false, -1);
ScanStatement statement = translated.plan.mainStatement.unwrap(ScanStatement.class);
assertTrue(statement.getPredicate().getIndexOperation() instanceof SecondaryIndexSeek);
try (DataScanner scan = server_1.getManager().scan(statement, translated.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(1, scan.consume().size());
}
}
String tableSpaceUUID;
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
{
ZookeeperMetadataStorageManager man = (ZookeeperMetadataStorageManager) server_1.getMetadataStorageManager();
tableSpaceUUID = man.describeTableSpace(TableSpace.DEFAULT).uuid;
LedgersInfo ledgersList = ZookeeperMetadataStorageManager.readActualLedgersListFromZookeeper(man.getZooKeeper(), testEnv.getPath() + "/ledgers", tableSpaceUUID);
assertEquals(2, ledgersList.getActiveLedgers().size());
}
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 5, "s", "5")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().checkpoint();
}
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
{
ZookeeperMetadataStorageManager man = (ZookeeperMetadataStorageManager) server_1.getMetadataStorageManager();
LedgersInfo ledgersList = ZookeeperMetadataStorageManager.readActualLedgersListFromZookeeper(man.getZooKeeper(), testEnv.getPath() + "/ledgers", tableSpaceUUID);
assertEquals(2, ledgersList.getActiveLedgers().size());
}
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 6, "s", "6")), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
{
ZookeeperMetadataStorageManager man = (ZookeeperMetadataStorageManager) server_1.getMetadataStorageManager();
LedgersInfo ledgersList = ZookeeperMetadataStorageManager.readActualLedgersListFromZookeeper(man.getZooKeeper(), testEnv.getPath() + "/ledgers", tableSpaceUUID);
assertEquals(2, ledgersList.getActiveLedgers().size());
}
server_1.getManager().checkpoint();
}
assertEquals(0, countErase.get());
LogSequenceNumber server2checkpointPosition;
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
// start server_2, and flush data locally
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
// wait for data to arrive on server_2
for (int i = 0; i < 100; i++) {
GetResult found = server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
if (found.found()) {
break;
}
Thread.sleep(100);
}
// force a checkpoint, data is flushed to disk
server_2.getManager().checkpoint();
server2checkpointPosition = server_2.getManager().getTableSpaceManager(TableSpace.DEFAULT).getLog().getLastSequenceNumber();
System.out.println("server2 checkpoint time: " + server2checkpointPosition);
}
}
// start again server_1, in order to create a new ledger
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
BookkeeperCommitLog ll = (BookkeeperCommitLog) server_1.getManager().getTableSpaceManager(TableSpace.DEFAULT).getLog();
// server_1 make much progress
ll.rollNewLedger();
ll.rollNewLedger();
ll.rollNewLedger();
ll.rollNewLedger();
ll.rollNewLedger();
ll.rollNewLedger();
ll.rollNewLedger();
ll.rollNewLedger();
// a checkpoint will delete old ledgers
server_1.getManager().checkpoint();
{
ZookeeperMetadataStorageManager man = (ZookeeperMetadataStorageManager) server_1.getMetadataStorageManager();
LedgersInfo ledgersList = ZookeeperMetadataStorageManager.readActualLedgersListFromZookeeper(man.getZooKeeper(), testEnv.getPath() + "/ledgers", tableSpaceUUID);
System.out.println("ledgerList: " + ledgersList);
assertEquals(1, ledgersList.getActiveLedgers().size());
assertTrue(!ledgersList.getActiveLedgers().contains(ledgersList.getFirstLedger()));
// we want to be sure that server_2 cannot recover from log
assertTrue(!ledgersList.getActiveLedgers().contains(server2checkpointPosition.ledgerId));
}
assertEquals(1, countErase.get());
// make server2 boot as leader, it will fence out server1
// but server1 is not writing so it won't know from BK
// it will see his new role from zookeeper (with a 'watch' notification)
server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server2", 1, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
// trying to become leader
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
assertFalse(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 10000, true));
}
// make server_1 leader again
server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server1", 1, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
// now server_2 must be able to boot, downloading data from server_1 and easing local state
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
assertFalse(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, true));
}
// make server_2 leader again
server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server2", 1, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
// stop server_1
server_1.close();
// it must have enough local data to boot
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, true));
}
}
}
use of herddb.log.LogSequenceNumber in project herddb by diennea.
the class BootFollowerTest method testFollowerBootError.
@Test
public void testFollowerBootError() throws Exception {
int size = 20_000;
final AtomicInteger callCount = new AtomicInteger();
// inject a temporary error during download
final AtomicInteger errorCount = new AtomicInteger(1);
SystemInstrumentation.addListener(new SystemInstrumentation.SingleInstrumentationPointListener("receiveTableDataChunk") {
@Override
public void acceptSingle(Object... args) throws Exception {
callCount.incrementAndGet();
if (errorCount.decrementAndGet() == 0) {
throw new Exception("synthetic error");
}
}
});
ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
serverconfig_1.set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
// disabled
serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_MAX_IDLE_TIME, 0);
ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath()).set(ServerConfiguration.PROPERTY_BOOT_FORCE_DOWNLOAD_SNAPSHOT, true).set(ServerConfiguration.PROPERTY_MEMORY_LIMIT_REFERENCE, 5_000_000).set(ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE, 200_000);
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).column("s", ColumnTypes.INTEGER).primaryKey("c").build();
server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
LogSequenceNumber lastSequenceNumberServer1 = server_1.getManager().getTableSpaceManager(TableSpace.DEFAULT).getLog().getLastSequenceNumber();
for (int i = 0; i < size; i++) {
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", i, "s", "1" + i)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
}
server_1.getManager().executeStatement(new AlterTableSpaceStatement(TableSpace.DEFAULT, new HashSet<>(Arrays.asList("server1", "server2")), "server1", 1, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
LogSequenceNumber lastSequenceNumberServer2 = server_2.getManager().getTableSpaceManager(TableSpace.DEFAULT).getLog().getLastSequenceNumber();
while (!lastSequenceNumberServer2.after(lastSequenceNumberServer1)) {
System.out.println("WAITING FOR server2 to be in sync....now it is a " + lastSequenceNumberServer2 + " vs " + lastSequenceNumberServer1);
lastSequenceNumberServer2 = server_2.getManager().getTableSpaceManager(TableSpace.DEFAULT).getLog().getLastSequenceNumber();
Thread.sleep(1000);
}
}
// reboot followerĖ
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
for (int i = 0; i < size; i++) {
GetResult found = server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(i), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
if (found.found()) {
break;
}
Thread.sleep(100);
}
}
assertEquals(3, callCount.get());
assertTrue(errorCount.get() <= 0);
}
}
use of herddb.log.LogSequenceNumber in project herddb by diennea.
the class DownloadTableSpaceTest method downloadTablespaceTest.
@Test
public void downloadTablespaceTest() throws Exception {
ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).primaryKey("c").build();
server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
for (int i = 0; i < 1000; i++) {
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", i)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
}
List<Map<String, Object>> logical_data = new ArrayList<>();
AtomicBoolean start = new AtomicBoolean();
try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()));
HDBConnection con = client.openConnection()) {
client.setClientSideMetadataProvider(new ZookeeperClientSideMetadataProvider(testEnv.getAddress(), testEnv.getTimeout(), testEnv.getPath()));
CountDownLatch count = new CountDownLatch(1);
con.dumpTableSpace(TableSpace.DEFAULT, new TableSpaceDumpReceiver() {
Table table;
@Override
public void start(LogSequenceNumber logSequenceNumber) throws DataStorageManagerException {
System.out.println("start at " + logSequenceNumber);
start.set(true);
}
@Override
public void finish(LogSequenceNumber logSequenceNumber) {
System.out.println("finish!");
count.countDown();
}
@Override
public void endTable() {
System.out.println("endTable");
table = null;
}
@Override
public void receiveTableDataChunk(List<Record> records) {
// System.out.println("receiveTableDataChunk " + records);
for (Record r : records) {
Map<String, Object> bean = r.toBean(table);
// System.out.println("received:" + bean);
logical_data.add(bean);
}
}
@Override
public void beginTable(DumpedTableMetadata table, Map<String, Object> stats) {
System.out.println("beginTable " + table);
this.table = table.table;
}
}, 89, false);
assertTrue(count.await(20, TimeUnit.SECONDS));
assertEquals(1000, logical_data.size());
assertTrue(start.get());
}
}
}
Aggregations