use of herddb.model.TableSpace in project herddb by diennea.
the class HerdDBCLI method printTableSpaceInfos.
private static void printTableSpaceInfos(boolean verbose, boolean ignoreerrors, Statement statement, TableSpaceMapper tableSpaceMapper, String schema, ZookeeperMetadataStorageManager clusterManager) throws SQLException, ScriptException, MetadataStorageManagerException {
if (clusterManager != null) {
TableSpace tablespace = clusterManager.describeTableSpace(schema);
if (tablespace == null) {
println("Unknown tablespace " + schema);
exitCode = 1;
System.exit(exitCode);
}
List<TableSpaceReplicaState> nodes = clusterManager.getTableSpaceReplicaState(tablespace.uuid);
println(" Tablespace: " + tablespace.name);
println(" Leader node: " + tablespace.leaderId);
println(" Replication nodes: " + tablespace.replicas);
println(" Expected replica count: " + tablespace.expectedReplicaCount);
println(" Max leader inactivity time: " + (tablespace.maxLeaderInactivityTime / 1000) + "s");
println(" UUID: " + tablespace.uuid);
if (nodes != null) {
println("");
println(" Replication nodes (systablespacereplicastate):");
if (nodes.isEmpty()) {
println("");
println(" No nodes to show");
}
for (TableSpaceReplicaState node : nodes) {
println("");
if (!tablespace.replicas.contains(node.nodeId)) {
println(" Node ID: " + node.nodeId + " (no more in replica list)");
} else {
println(" Node ID: " + node.nodeId);
}
println(" Mode: " + node.mode);
println(" Last activity: " + new java.sql.Timestamp(node.timestamp));
println(" Inactivity time: " + (Float.valueOf(System.currentTimeMillis() - node.timestamp) / 1000) + "s");
}
}
println("");
} else {
ExecuteStatementResult tablespace = executeStatement(verbose, ignoreerrors, false, false, "select * from systablespaces where tablespace_name='" + schema + "'", statement, tableSpaceMapper, true, false);
ExecuteStatementResult nodes = executeStatement(verbose, ignoreerrors, false, false, "select * from systablespacereplicastate where tablespace_name='" + schema + "'", statement, tableSpaceMapper, true, false);
if (tablespace.results.isEmpty()) {
println("Unknown tablespace " + schema);
exitCode = 1;
System.exit(exitCode);
}
println("");
Map<String, Object> ts = tablespace.results.get(0);
println(" Tablespace: " + ts.get("tablespace_name"));
println(" Leader node: " + ts.get("leader"));
println(" Replication nodes: " + ts.get("replica"));
println(" Expected replica count: " + ts.get("expectedreplicacount"));
println(" Max leader inactivity time: " + (Float.valueOf((String) ts.get("maxleaderinactivitytime")) / 1000) + "s");
println(" UUID: " + ts.get("uuid"));
if (nodes != null) {
println("");
println(" Replication nodes (systablespacereplicastate):");
if (nodes.results.isEmpty()) {
println("");
println(" No nodes to show");
}
for (Map<String, Object> node : nodes.results) {
println("");
println(" Node ID: " + node.get("nodeid"));
println(" Mode: " + node.get("mode"));
println(" Last activity: " + node.get("timestamp"));
println(" Inactivity time: " + (Float.valueOf((String) node.get("inactivitytime")) / 1000) + "s");
println(" Max leader inactivity time: " + (Float.valueOf((String) node.get("maxleaderinactivitytime")) / 1000) + "s");
}
}
println("");
}
}
use of herddb.model.TableSpace in project herddb by diennea.
the class AlterTablespaceSQLTest method escapeTableSpaceName.
@Test
public void escapeTableSpaceName() throws Exception {
String nodeId = "localhost";
try (DBManager manager = new DBManager(nodeId, new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
manager.start();
assertTrue(manager.waitForTablespace(TableSpace.DEFAULT, 10000));
execute(manager, "CREATE TABLESPACE `default`,'leader:" + nodeId + "'", Collections.emptyList());
try {
execute(manager, "EXECUTE CREATETABLESPACE `default`,'leader:othernode'", Collections.emptyList());
fail();
} catch (TableSpaceAlreadyExistsException err) {
}
execute(manager, "EXECUTE ALTERTABLESPACE `default`,`replica:" + nodeId + ",othernode`,'expectedReplicaCount:2'", Collections.emptyList());
execute(manager, "EXECUTE ALTERTABLESPACE 'default','leader:othernode'", Collections.emptyList());
execute(manager, "EXECUTE ALTERTABLESPACE 'default','expectedReplicaCount:12'", Collections.emptyList());
TableSpace ttt3 = manager.getMetadataStorageManager().describeTableSpace("default");
assertEquals("othernode", ttt3.leaderId);
assertEquals(12, ttt3.expectedReplicaCount);
assertTrue(ttt3.replicas.contains("othernode"));
assertTrue(ttt3.replicas.contains(nodeId));
try (DataScanner scan = scan(manager, "SELECT * FROM SYSTABLESPACES", Collections.emptyList())) {
List<DataAccessor> tuples = scan.consume();
assertEquals(2, tuples.size());
for (DataAccessor t : tuples) {
System.out.println("tablespace: " + t.toMap());
assertNotNull(t.get("expectedreplicacount"));
assertNotNull(t.get("tablespace_name"));
assertNotNull(t.get("replica"));
assertNotNull(t.get("leader"));
}
}
try (DataScanner scan = scan(manager, "SELECT expectedreplicacount FROM SYSTABLESPACES where tablespace_name='default'", Collections.emptyList())) {
List<DataAccessor> tuples = scan.consume();
assertEquals(1, tuples.size());
for (DataAccessor t : tuples) {
System.out.println("tablespace: " + t.toMap());
assertEquals(12, t.get("expectedreplicacount"));
}
}
}
}
Aggregations