use of herddb.server.ServerConfiguration in project herddb by diennea.
the class SimpleFollowerTest method followerMustNoRollbackAbandonedTransactions.
@Test
public void followerMustNoRollbackAbandonedTransactions() 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());
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_ABANDONED_TRANSACTIONS_TIMEOUT, 1).set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath());
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).primaryKey("c").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().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 1)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 2)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 3)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 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);
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
// start a transaction
DMLStatementExecutionResult executeUpdateRes = server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 5)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.AUTOTRANSACTION_TRANSACTION);
long tx = executeUpdateRes.transactionId;
assertTrue(tx > 0);
// wait for transaction to arrive on server_2
TestUtils.waitForCondition(() -> {
return server_2.getManager().getTableSpaceManager(TableSpace.DEFAULT).getTransaction(tx) != null;
}, TestUtils.NOOP, 100);
// make the transaction appear "abandoned" to server_2
Thread.sleep(1000 + (int) server_2.getManager().getAbandonedTransactionsTimeout());
server_2.getManager().triggerActivator(ActivatorRunRequest.FULL);
assertFalse(server_2.getManager().getTableSpaceManager(TableSpace.DEFAULT).isFailed());
}
// restart the follower again
try (Server server_2 = new Server(serverconfig_2)) {
server_2.start();
assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
}
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class CheckpointTest method rebuildSmallPages.
/**
* Rebuild all small pages
*/
@Test
public void rebuildSmallPages() throws Exception {
Path dataPath = folder.newFolder("data").toPath();
Path logsPath = folder.newFolder("logs").toPath();
Path metadataPath = folder.newFolder("metadata").toPath();
Path tmpDir = folder.newFolder("tmpDir").toPath();
String nodeId = "localhost";
ServerConfiguration config1 = newServerConfigurationWithAutoPort();
config1.set(ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE, 1024L);
int records = 1000;
int keylen = 25;
int strlen = 50;
int originalPages;
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmpDir, null, config1, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string, s1 string, n1 int, primary key(k1))", Collections.emptyList());
for (int i = 0; i < records; ++i) {
executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList(RandomString.getInstance().nextString(keylen), RandomString.getInstance().nextString(strlen), Integer.valueOf(i)));
}
manager.checkpoint();
String uuid = manager.getMetadataStorageManager().describeTableSpace("tblspace1").uuid;
String tableUuid = manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable().uuid;
originalPages = manager.getDataStorageManager().getActualNumberOfPages(uuid, tableUuid);
assertTrue(originalPages > 10);
}
ServerConfiguration config2 = newServerConfigurationWithAutoPort();
config2.set(ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE, 2048L);
config2.set(ServerConfiguration.PROPERTY_COMPACTION_DURATION, -1L);
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmpDir, null, config2, null)) {
manager.start();
assertTrue(manager.waitForTablespace("tblspace1", 20000));
manager.checkpoint();
String tableUuid = manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable().uuid;
String uuid = manager.getMetadataStorageManager().describeTableSpace("tblspace1").uuid;
int pages = manager.getDataStorageManager().getActualNumberOfPages(uuid, tableUuid);
/* There are at least half pages! */
assertTrue(pages <= (originalPages / 2) + (originalPages % 2));
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class CheckpointTest method restartTest.
/**
* Reload dirty pages on restart
*/
@Test
public void restartTest() throws Exception {
Path dataPath = folder.newFolder("data").toPath();
Path logsPath = folder.newFolder("logs").toPath();
Path metadataPath = folder.newFolder("metadata").toPath();
Path tmpDir = folder.newFolder("tmpDir").toPath();
String nodeId = "localhost";
ServerConfiguration config1 = newServerConfigurationWithAutoPort();
/* Disable page compaction (avoid compaction of dirty page) */
config1.set(ServerConfiguration.PROPERTY_FILL_PAGE_THRESHOLD, 0.0D);
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmpDir, null, config1, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (K1 string ,s1 string,n1 int, primary key(k1))", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey", "a", Integer.valueOf(1234))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey2", "a", Integer.valueOf(1234))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey3", "a", Integer.valueOf(1234))).getUpdateCount());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,s1,n1) values(?,?,?)", Arrays.asList("mykey4", "a", Integer.valueOf(1234))).getUpdateCount());
manager.checkpoint();
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set s1=? where k1=?", Arrays.asList("b", "mykey4")).getUpdateCount());
manager.checkpoint();
assertEquals(3, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getLoadedpages());
assertEquals(1, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getDirtypages());
}
try (DBManager manager = new DBManager("localhost", new FileMetadataStorageManager(metadataPath), new FileDataStorageManager(dataPath), new FileCommitLogManager(logsPath), tmpDir, null, config1, null)) {
manager.start();
manager.waitForTablespace("tblspace1", 10000);
assertEquals(1, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getLoadedpages());
assertEquals(1, manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getStats().getDirtypages());
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class BookKeeperCommitLogTest method testMaxLedgerSize.
@Test
public void testMaxLedgerSize() throws Exception {
final String tableSpaceUUID = UUID.randomUUID().toString();
final String name = TableSpace.DEFAULT;
final String nodeid = "nodeid";
final int maxLedgerSize = 1024;
final LogEntry entry = LogEntryFactory.beginTransaction(1);
final int estimateSize = entry.serialize().length;
final int numberOfLedgers = 10;
final int numberOfEntries = 1 + numberOfLedgers * maxLedgerSize / estimateSize;
ServerConfiguration serverConfiguration = newServerConfigurationWithAutoPort();
try (ZookeeperMetadataStorageManager man = new ZookeeperMetadataStorageManager(testEnv.getAddress(), testEnv.getTimeout(), testEnv.getPath());
BookkeeperCommitLogManager logManager = new BookkeeperCommitLogManager(man, serverConfiguration, NullStatsLogger.INSTANCE)) {
logManager.setMaxLedgerSizeBytes(maxLedgerSize);
man.start();
logManager.start();
try (BookkeeperCommitLog writer = logManager.createCommitLog(tableSpaceUUID, name, nodeid)) {
// do not pollute the count with NOOP entries
writer.setWriteLedgerHeader(false);
writer.startWriting(1);
for (int i = 0; i < numberOfEntries; i++) {
writer.log(entry, false);
}
writer.log(entry, true).getLogSequenceNumber();
}
try (BookkeeperCommitLog reader = logManager.createCommitLog(tableSpaceUUID, name, nodeid)) {
List<Map.Entry<LogSequenceNumber, LogEntry>> list = new ArrayList<>();
Set<Long> ledgerIds = new HashSet<>();
reader.recovery(LogSequenceNumber.START_OF_TIME, (a, b) -> {
if (b.type != LogEntryType.NOOP) {
list.add(new AbstractMap.SimpleImmutableEntry<>(a, b));
ledgerIds.add(a.ledgerId);
}
}, false);
assertEquals(numberOfEntries + 1, list.size());
assertEquals(numberOfLedgers, ledgerIds.size());
}
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class BookieNotAvailableTest method testBookieNoAvailableNoTransaction.
@Test
public void testBookieNoAvailableNoTransaction() 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());
serverconfig_1.set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
try (Server server = new Server(serverconfig_1)) {
server.start();
server.waitForStandaloneBoot();
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).primaryKey("c").build();
server.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 1)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 2)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
server.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 3)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
TableSpaceManager tableSpaceManager = server.getManager().getTableSpaceManager(TableSpace.DEFAULT);
BookkeeperCommitLog log = (BookkeeperCommitLog) tableSpaceManager.getLog();
long ledgerId = log.getLastSequenceNumber().ledgerId;
assertTrue(ledgerId >= 0);
// we do not want auto-recovery
server.getManager().setActivatorPauseStatus(true);
testEnv.pauseBookie();
try {
server.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 4)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
fail();
} catch (StatementExecutionException expected) {
}
testEnv.resumeBookie();
while (true) {
System.out.println("status leader:" + tableSpaceManager.isLeader() + " failed:" + tableSpaceManager.isFailed());
if (tableSpaceManager.isFailed()) {
break;
}
Thread.sleep(100);
}
server.getManager().setActivatorPauseStatus(false);
server.getManager().triggerActivator(ActivatorRunRequest.TABLESPACEMANAGEMENT);
while (true) {
TableSpaceManager tableSpaceManager_after_failure = server.getManager().getTableSpaceManager(TableSpace.DEFAULT);
System.out.println("tableSpaceManager_after_failure:" + tableSpaceManager_after_failure);
System.out.println("tableSpaceManager:" + tableSpaceManager);
if (tableSpaceManager_after_failure != null && tableSpaceManager_after_failure != tableSpaceManager) {
break;
}
Thread.sleep(1000);
server.getManager().triggerActivator(ActivatorRunRequest.TABLESPACEMANAGEMENT);
}
TableSpaceManager tableSpaceManager_after_failure = server.getManager().getTableSpaceManager(TableSpace.DEFAULT);
Assert.assertNotNull(tableSpaceManager_after_failure);
assertNotSame(tableSpaceManager_after_failure, tableSpaceManager);
assertTrue(!tableSpaceManager_after_failure.isFailed());
server.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", 4)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
try (DataScanner scan = scan(server.getManager(), "select * from t1", Collections.emptyList())) {
assertEquals(4, scan.consume().size());
}
}
}
Aggregations