use of herddb.model.commands.GetStatement in project herddb by diennea.
the class SimpleTransactionTest method testInsertThenDelete.
@Test
public void testInsertThenDelete() throws Exception {
Bytes key = Bytes.from_string("key1");
long tx = beginTransaction();
{
Record record = new Record(key, Bytes.from_int(0));
InsertStatement st = new InsertStatement(tableSpace, tableName, record);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
}
{
DeleteStatement st = new DeleteStatement(tableSpace, tableName, key, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
}
commitTransaction(tx);
GetResult get = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(get.found());
}
use of herddb.model.commands.GetStatement in project herddb by diennea.
the class RawSQLTest method basicTest.
@Test
public void basicTest() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
manager.waitForTablespace("tblspace1", 10000);
execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1234))).getUpdateCount());
{
GetResult result = manager.get(new GetStatement("tblspace1", "tsql", Bytes.from_string("mykey"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
assertEquals(result.getRecord().key, Bytes.from_string("mykey"));
Map<String, Object> finalRecord = result.getRecord().toBean(manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable());
assertEquals(RawString.of("mykey"), finalRecord.get("k1"));
assertEquals(Integer.valueOf(1234), finalRecord.get("n1"));
}
{
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=? where k1 = ?", Arrays.asList(Integer.valueOf(999), "mykey")).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=? where k1 = ? and n1 = ?", Arrays.asList(Integer.valueOf(100), "mykey", Integer.valueOf(999))).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=? where k1 = ? and (n1 = ? or n1 <> ?)", Arrays.asList(Integer.valueOf(999), "mykey", Integer.valueOf(100), Integer.valueOf(1000))).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=? where k1 = ? and (n1 <> ?)", Arrays.asList(Integer.valueOf(34), "mykey", Integer.valueOf(15))).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=? where k1 = ? and not (n1 <> ?)", Arrays.asList(Integer.valueOf(999), "mykey", Integer.valueOf(34))).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement("tblspace1", "tsql", Bytes.from_string("mykey"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
assertEquals(result.getRecord().key, Bytes.from_string("mykey"));
Map<String, Object> finalRecord = result.getRecord().toBean(manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable());
assertEquals(RawString.of("mykey"), finalRecord.get("k1"));
assertEquals(Integer.valueOf(999), finalRecord.get("n1"));
}
{
TranslatedQuery translate1 = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.tsql where k1 = ?", Arrays.asList("mykey"), false, true, false, -1);
GetStatement st_get = (GetStatement) translate1.plan.mainStatement;
GetResult result = manager.get(st_get, translate1.context, TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
assertEquals(result.getRecord().key, Bytes.from_string("mykey"));
Map<String, Object> finalRecord = result.getRecord().toBean(manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable());
assertEquals(RawString.of("mykey"), finalRecord.get("k1"));
assertEquals(Integer.valueOf(999), finalRecord.get("n1"));
}
{
TranslatedQuery translate1 = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.tsql where k1 = ? and n1=?", Arrays.asList("mykey", 999), false, true, false, -1);
GetStatement st_get_with_condition = (GetStatement) translate1.plan.mainStatement;
GetResult result = manager.get(st_get_with_condition, translate1.context, TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
assertEquals(result.getRecord().key, Bytes.from_string("mykey"));
Map<String, Object> finalRecord = result.getRecord().toBean(manager.getTableSpaceManager("tblspace1").getTableManager("tsql").getTable());
assertEquals(RawString.of("mykey"), finalRecord.get("k1"));
assertEquals(Integer.valueOf(999), finalRecord.get("n1"));
}
{
TranslatedQuery translate1 = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.tsql where k1 = ? and n1=?", Arrays.asList("mykey", 9992), false, true, false, -1);
GetStatement st_get_with_wrong_condition = (GetStatement) translate1.plan.mainStatement;
GetResult result = manager.get(st_get_with_wrong_condition, translate1.context, TransactionContext.NO_TRANSACTION);
assertFalse(result.found());
}
{
assertEquals(0, executeUpdate(manager, "DELETE FROM tblspace1.tsql where k1 = ? and n1 = ?", Arrays.asList("mykey", 123)).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "DELETE FROM tblspace1.tsql where k1 = ?", Arrays.asList("mykey")).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement("tblspace1", "tsql", Bytes.from_string("mykey"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(result.found());
}
{
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1234))).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement("tblspace1", "tsql", Bytes.from_string("mykey"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
}
{
assertEquals(1, executeUpdate(manager, "DELETE FROM tblspace1.tsql where k1 = ? and n1=?", Arrays.asList("mykey", 1234)).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement("tblspace1", "tsql", Bytes.from_string("mykey"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(result.found());
}
{
assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.tsql(k1,n1) values('mykey2',1234)", Collections.emptyList()).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=2135 where k1 = 'mykey2'", Collections.emptyList()).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=2138,s1='foo' where k1 = 'mykey2' and s1 is null", Collections.emptyList()).getUpdateCount());
}
{
TranslatedQuery translate1 = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.tsql where k1 ='mykey2'", Collections.emptyList(), true, true, false, -1);
ScanStatement scan = translate1.plan.mainStatement.unwrap(ScanStatement.class);
try (DataScanner scan1 = manager.scan(scan, translate1.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(1, scan1.consume().size());
}
}
{
TranslatedQuery translate1 = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 FROM tblspace1.tsql where k1 ='mykey2'", Collections.emptyList(), true, true, false, -1);
try (DataScanner scan1 = ((ScanResult) manager.executePlan(translate1.plan, translate1.context, TransactionContext.NO_TRANSACTION)).dataScanner) {
List<DataAccessor> records = scan1.consume();
assertEquals(1, records.size());
System.out.println("records:" + records);
assertEquals(1, records.get(0).getFieldNames().length);
assertEquals(1, records.get(0).toMap().size());
assertEquals("k1", records.get(0).getFieldNames()[0]);
assertEquals(RawString.of("mykey2"), records.get(0).get(0));
}
}
{
TranslatedQuery translate1 = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 theKey FROM tblspace1.tsql where k1 ='mykey2'", Collections.emptyList(), true, true, false, -1);
try (DataScanner scan1 = ((ScanResult) manager.executePlan(translate1.plan, translate1.context, TransactionContext.NO_TRANSACTION)).dataScanner) {
List<DataAccessor> records = scan1.consume();
assertEquals(1, records.size());
assertEquals(1, records.get(0).getFieldNames().length);
assertEquals(1, records.get(0).toMap().size());
assertEquals("thekey", records.get(0).getFieldNames()[0].toLowerCase());
System.out.println("type: " + records.get(0).getClass());
assertEquals(RawString.of("mykey2"), records.get(0).get(0));
}
}
{
TranslatedQuery translate1 = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT k1 as theKey,'one' as theStringConstant,3 LongConstant FROM tblspace1.tsql where k1 ='mykey2'", Collections.emptyList(), true, true, false, -1);
try (DataScanner scan1 = ((ScanResult) manager.executePlan(translate1.plan, translate1.context, TransactionContext.NO_TRANSACTION)).dataScanner) {
List<DataAccessor> records = scan1.consume();
assertEquals(1, records.size());
assertEquals(3, records.get(0).getFieldNames().length);
assertEquals(3, records.get(0).toMap().size());
assertEquals("thekey", records.get(0).getFieldNames()[0].toLowerCase());
assertEquals(RawString.of("mykey2"), records.get(0).get(0));
assertEquals("thestringconstant", records.get(0).getFieldNames()[1].toLowerCase());
assertEquals(RawString.of("one"), records.get(0).get(1));
assertEquals("longconstant", records.get(0).getFieldNames()[2].toLowerCase());
assertEquals(3, ((Number) records.get(0).get(2)).longValue());
}
}
{
TranslatedQuery translate1 = manager.getPlanner().translate(TableSpace.DEFAULT, "SELECT * FROM tblspace1.tsql where k1 ='mykey2' and s1 is not null", Collections.emptyList(), true, true, false, -1);
ScanStatement scan = translate1.plan.mainStatement.unwrap(ScanStatement.class);
try (DataScanner scan1 = manager.scan(scan, translate1.context, TransactionContext.NO_TRANSACTION)) {
assertEquals(1, scan1.consume().size());
}
}
{
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=2138,s1='bar' where k1 = 'mykey2' and s1 is not null", Collections.emptyList()).getUpdateCount());
}
{
assertEquals(0, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=2138,s1='bar' where k1 = 'mykey2' and s1 is null", Collections.emptyList()).getUpdateCount());
}
{
assertEquals(0, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=2138,s1='bar' where k1 = 'mykey2' and not (s1 is not null)", Collections.emptyList()).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "UPDATE tblspace1.tsql set n1=2138,s1='bar' where k1 = 'mykey2' and not (s1 is null)", Collections.emptyList()).getUpdateCount());
}
{
assertEquals(1, executeUpdate(manager, "DELETE FROM tblspace1.tsql where k1 = 'mykey2' and s1 is not null", Collections.emptyList()).getUpdateCount());
assertEquals(0, executeUpdate(manager, "DELETE FROM tblspace1.tsql where k1 = 'mykey2' and s1 is not null", Collections.emptyList()).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement("tblspace1", "tsql", Bytes.from_string("mykey2"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(result.found());
}
{
TransactionResult result = (TransactionResult) execute(manager, "EXECUTE BEGINTRANSACTION 'tblspace1'", Collections.emptyList());
long tx = result.getTransactionId();
execute(manager, "EXECUTE COMMITTRANSACTION 'tblspace1'," + tx, Collections.emptyList());
}
{
TransactionResult result = (TransactionResult) execute(manager, "EXECUTE BEGINTRANSACTION 'tblspace1'", Collections.emptyList());
long tx = result.getTransactionId();
execute(manager, "EXECUTE ROLLBACKTRANSACTION 'tblspace1'," + tx, Collections.emptyList());
}
}
}
use of herddb.model.commands.GetStatement in project herddb by diennea.
the class MultiBookieTest method testFollowWithDownBookie.
@Test
public void testFollowWithDownBookie() throws Exception {
// two bookies
this.testEnv.startNewBookie();
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_BOOKKEEPER_ENSEMBLE, 2);
serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_WRITEQUORUMSIZE, 2);
serverconfig_1.set(ServerConfiguration.PROPERTY_BOOKKEEPER_ACKQUORUMSIZE, 2);
List<BookieId> bookies;
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();
Index index = Index.builder().onTable(table).type(Index.TYPE_BRIN).column("s", ColumnTypes.STRING).build();
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());
}
BookkeeperCommitLog log = (BookkeeperCommitLog) server_1.getManager().getTableSpaceManager(TableSpace.DEFAULT).getLog();
bookies = log.getWriter().getOut().getLedgerMetadata().getAllEnsembles().firstEntry().getValue();
}
// we must be able to recover even if one bookie is down
for (BookieId bAddress : bookies) {
this.testEnv.pauseBookie(bAddress);
ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath()).set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
try (Server server_2 = new Server(serverconfig_2)) {
server_2.getManager().setActivatorPauseStatus(true);
server_2.start();
assertTrue(server_2.getManager().isTableSpaceLocallyRecoverable(server_2.getMetadataStorageManager().describeTableSpace(TableSpace.DEFAULT)));
server_2.getManager().setActivatorPauseStatus(false);
assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
assertTrue(server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
}
this.testEnv.resumeBookie(bAddress);
}
// we must be able to recover even if one bookie is down
for (BookieId bAddress : bookies) {
this.testEnv.stopBookie(bAddress);
ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath()).set(ServerConfiguration.PROPERTY_ENFORCE_LEADERSHIP, false);
try (Server server_2 = new Server(serverconfig_2)) {
server_2.getManager().setActivatorPauseStatus(true);
server_2.start();
assertTrue(server_2.getManager().isTableSpaceLocallyRecoverable(server_2.getMetadataStorageManager().describeTableSpace(TableSpace.DEFAULT)));
server_2.getManager().setActivatorPauseStatus(false);
assertTrue(server_2.getManager().waitForTablespace(TableSpace.DEFAULT, 60000, false));
assertTrue(server_2.getManager().get(new GetStatement(TableSpace.DEFAULT, "t1", Bytes.from_int(1), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).found());
}
this.testEnv.startStoppedBookie(bAddress);
}
}
use of herddb.model.commands.GetStatement in project herddb by diennea.
the class SimpleClusterDisklessTest method test.
@Test
public void test() throws Exception {
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("0"));
InsertStatement st = new InsertStatement(tableSpace, tableName, record);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
assertEquals(0, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableName));
manager.checkpoint();
String tableUuid = manager.getTableSpaceManager(tableSpace).getTableManager(tableName).getTable().uuid;
assertNotNull(dataStorageManager.readPage(tableSpaceUUID, tableUuid, 1L));
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
GetResult result = manager.get(new GetStatement(tableSpace, tableName, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
}
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("5"));
UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
// a new page must be allocated
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("6"));
UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("7"));
UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
// only a new page must be allocated, not two more
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
DeleteStatement st = new DeleteStatement(tableSpace, tableName, Bytes.from_string("key1"), null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
GetResult result = manager.get(new GetStatement(tableSpace, tableName, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(result.found());
}
// a delete does not trigger new pages in this case
manager.checkpoint();
assertEquals(0, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
assertEquals(1, manager.executeUpdate(new InsertStatement(tableSpace, tableName, new Record(Bytes.from_string("key2"), Bytes.from_string("50"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
assertEquals(1, manager.executeUpdate(new InsertStatement(tableSpace, tableName, new Record(Bytes.from_string("key3"), Bytes.from_string("60"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
DeleteStatement st = new DeleteStatement(tableSpace, tableName, Bytes.from_string("key2"), null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
// a new page, containg the key3 record is needed
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
Holder<TableStatus> _tableStatus = new Holder<>();
dataStorageManager.fullTableScan(tableSpaceUUID, tableUuid, new FullTableScanConsumer() {
@Override
public void acceptTableStatus(TableStatus tableStatus) {
_tableStatus.value = tableStatus;
}
});
for (long pageId : _tableStatus.value.activePages.keySet()) {
List<Record> records = dataStorageManager.readPage(tableSpaceUUID, tableUuid, pageId);
System.out.println("PAGE #" + pageId + " records :" + records);
}
assertEquals(1, _tableStatus.value.activePages.size());
}
use of herddb.model.commands.GetStatement in project herddb by diennea.
the class SimpleDMLFileTest method test.
@Test
public void test() throws Exception {
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("0"));
InsertStatement st = new InsertStatement(tableSpace, tableName, record);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
String tableUuid = manager.getTableSpaceManager(tableSpace).getTableManager(tableName).getTable().uuid;
boolean notexist = false;
try {
dataStorageManager.readPage(tableSpaceUUID, tableUuid, 1L);
} catch (DataPageDoesNotExistException ex) {
notexist = true;
} finally {
assertTrue(notexist);
}
assertEquals(0, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
manager.checkpoint();
assertNotNull(dataStorageManager.readPage(tableSpaceUUID, tableUuid, 1L));
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
GetResult result = manager.get(new GetStatement(tableSpace, tableName, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
}
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("5"));
UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
// a new page must be allocated
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("6"));
UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
{
Record record = new Record(Bytes.from_string("key1"), Bytes.from_string("7"));
UpdateStatement st = new UpdateStatement(tableSpace, tableName, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
// only a new page must be allocated, not two more
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
DeleteStatement st = new DeleteStatement(tableSpace, tableName, Bytes.from_string("key1"), null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
GetResult result = manager.get(new GetStatement(tableSpace, tableName, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(result.found());
}
// a delete does not trigger new pages in this case
manager.checkpoint();
assertEquals(0, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
assertEquals(1, manager.executeUpdate(new InsertStatement(tableSpace, tableName, new Record(Bytes.from_string("key2"), Bytes.from_string("50"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
assertEquals(1, manager.executeUpdate(new InsertStatement(tableSpace, tableName, new Record(Bytes.from_string("key3"), Bytes.from_string("60"))), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
manager.checkpoint();
assertEquals(1, dataStorageManager.getActualNumberOfPages(tableSpaceUUID, tableUuid));
{
DeleteStatement st = new DeleteStatement(tableSpace, tableName, Bytes.from_string("key2"), null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
// a new page, containg the key3 record is needed
manager.checkpoint();
}
Aggregations