use of herddb.model.TableSpace in project herddb by diennea.
the class TableSpaceManager method start.
void start() throws DataStorageManagerException, LogNotAvailableException, MetadataStorageManagerException, DDLException {
TableSpace tableSpaceInfo = metadataStorageManager.describeTableSpace(tableSpaceName);
bootSystemTables();
if (virtual) {
startAsLeader(1);
} else {
dataStorageManager.initTablespace(tableSpaceUUID);
recover(tableSpaceInfo);
LOGGER.log(Level.INFO, " after recovery of tableSpace {0}, actualLogSequenceNumber:{1}", new Object[] { tableSpaceName, actualLogSequenceNumber });
tableSpaceInfo = metadataStorageManager.describeTableSpace(tableSpaceName);
if (tableSpaceInfo.leaderId.equals(nodeId)) {
startAsLeader(tableSpaceInfo.expectedReplicaCount);
} else {
startAsFollower();
}
}
}
use of herddb.model.TableSpace in project herddb by diennea.
the class TableSpaceManager method downloadTableSpaceData.
private void downloadTableSpaceData() throws MetadataStorageManagerException, DataStorageManagerException, LogNotAvailableException {
TableSpace tableSpaceData = metadataStorageManager.describeTableSpace(tableSpaceName);
String leaderId = tableSpaceData.leaderId;
if (this.nodeId.equals(leaderId)) {
throw new DataStorageManagerException("cannot download data of tableSpace " + tableSpaceName + " from myself");
}
Optional<NodeMetadata> leaderAddress = metadataStorageManager.listNodes().stream().filter(n -> n.nodeId.equals(leaderId)).findAny();
if (!leaderAddress.isPresent()) {
throw new DataStorageManagerException("cannot download data of tableSpace " + tableSpaceName + " from leader " + leaderId + ", no metadata found");
}
// ensure we do not have any data on disk and in memory
actualLogSequenceNumber = LogSequenceNumber.START_OF_TIME;
newTransactionId.set(0);
LOGGER.log(Level.INFO, "tablespace " + tableSpaceName + " at downloadTableSpaceData " + tables + ", " + indexes + ", " + transactions);
for (AbstractTableManager manager : tables.values()) {
// and all indexes
if (!manager.isSystemTable()) {
manager.dropTableData();
}
manager.close();
}
tables.clear();
// this map should be empty
for (AbstractIndexManager manager : indexes.values()) {
manager.dropIndexData();
manager.close();
}
indexes.clear();
transactions.clear();
dataStorageManager.eraseTablespaceData(tableSpaceUUID);
NodeMetadata nodeData = leaderAddress.get();
ClientConfiguration clientConfiguration = new ClientConfiguration(dbmanager.getTmpDirectory());
clientConfiguration.set(ClientConfiguration.PROPERTY_CLIENT_USERNAME, dbmanager.getServerToServerUsername());
clientConfiguration.set(ClientConfiguration.PROPERTY_CLIENT_PASSWORD, dbmanager.getServerToServerPassword());
// always use network, we want to run tests with this case
clientConfiguration.set(ClientConfiguration.PROPERTY_CLIENT_CONNECT_LOCALVM_SERVER, false);
try (HDBClient client = new HDBClient(clientConfiguration)) {
client.setClientSideMetadataProvider(new ClientSideMetadataProvider() {
@Override
public String getTableSpaceLeader(String tableSpace) throws ClientSideMetadataProviderException {
return leaderId;
}
@Override
public ServerHostData getServerHostData(String nodeId) throws ClientSideMetadataProviderException {
return new ServerHostData(nodeData.host, nodeData.port, "?", nodeData.ssl, Collections.emptyMap());
}
});
try (HDBConnection con = client.openConnection()) {
ReplicaFullTableDataDumpReceiver receiver = new ReplicaFullTableDataDumpReceiver(this);
int fetchSize = 10000;
con.dumpTableSpace(tableSpaceName, receiver, fetchSize, false);
receiver.getLatch().get(1, TimeUnit.HOURS);
this.actualLogSequenceNumber = receiver.logSequenceNumber;
LOGGER.log(Level.INFO, tableSpaceName + " After download local actualLogSequenceNumber is " + actualLogSequenceNumber);
} catch (ClientSideMetadataProviderException | HDBException | InterruptedException | ExecutionException | TimeoutException internalError) {
LOGGER.log(Level.SEVERE, tableSpaceName + " error downloading snapshot", internalError);
throw new DataStorageManagerException(internalError);
}
}
}
use of herddb.model.TableSpace in project herddb by diennea.
the class DBManager method tryBecomeLeaderFor.
private boolean tryBecomeLeaderFor(TableSpace tableSpace) throws DDLException, MetadataStorageManagerException {
if (!isTableSpaceLocallyRecoverable(tableSpace)) {
LOGGER.log(Level.INFO, "local node {0} cannot become leader of {1} (current is {2})." + "Cannot boot tablespace locally (not enough data, last checkpoint + log)", new Object[] { nodeId, tableSpace.name, tableSpace.leaderId });
return false;
}
LOGGER.log(Level.INFO, "node {0}, try to become leader of {1} (prev was {2})", new Object[] { nodeId, tableSpace.name, tableSpace.leaderId });
TableSpace.Builder newTableSpaceBuilder = TableSpace.builder().cloning(tableSpace).leader(nodeId);
TableSpace newTableSpace = newTableSpaceBuilder.build();
boolean ok = metadataStorageManager.updateTableSpace(newTableSpace, tableSpace);
if (!ok) {
LOGGER.log(Level.SEVERE, "node {0} updating tableSpace {1} try to become leader failed", new Object[] { nodeId, tableSpace.name });
return false;
} else {
LOGGER.log(Level.SEVERE, "node {0} updating tableSpace {1} try to become leader succeeded", new Object[] { nodeId, tableSpace.name });
return true;
}
}
use of herddb.model.TableSpace in project herddb by diennea.
the class DBManager method alterTableSpace.
private StatementExecutionResult alterTableSpace(AlterTableSpaceStatement alterTableSpaceStatement) throws StatementExecutionException {
TableSpace tableSpace;
try {
TableSpace previous = metadataStorageManager.describeTableSpace(alterTableSpaceStatement.getTableSpace());
if (previous == null) {
throw new TableSpaceDoesNotExistException(alterTableSpaceStatement.getTableSpace());
}
try {
tableSpace = TableSpace.builder().cloning(previous).leader(alterTableSpaceStatement.getLeaderId()).name(alterTableSpaceStatement.getTableSpace()).replicas(alterTableSpaceStatement.getReplicas()).expectedReplicaCount(alterTableSpaceStatement.getExpectedReplicaCount()).maxLeaderInactivityTime(alterTableSpaceStatement.getMaxleaderinactivitytime()).build();
} catch (IllegalArgumentException invalid) {
throw new StatementExecutionException("invalid ALTER TABLESPACE statement: " + invalid.getMessage(), invalid);
}
metadataStorageManager.updateTableSpace(tableSpace, previous);
triggerActivator(ActivatorRunRequest.FULL);
return new DDLStatementExecutionResult(TransactionContext.NOTRANSACTION_ID);
} catch (Exception err) {
throw new StatementExecutionException(err);
}
}
use of herddb.model.TableSpace in project herddb by diennea.
the class HerdDBCLI method alterTablespace.
private static void alterTablespace(ZookeeperMetadataStorageManager clusterManager, String schema, String param, String values) throws SQLException, ScriptException, MetadataStorageManagerException {
if (clusterManager == null) {
println("You are not managing a cluster. This command cannot be used");
exitCode = 1;
System.exit(exitCode);
return;
}
TableSpace tableSpace = clusterManager.describeTableSpace(schema);
if (tableSpace == null) {
println("Cannot find tablespace " + schema);
exitCode = 1;
System.exit(exitCode);
return;
}
TableSpace.Builder newMetadata = TableSpace.builder().cloning(tableSpace);
switch(param) {
case "expectedreplicacount":
int expectedreplicacount = Integer.parseInt(values);
if (expectedreplicacount < 0 || expectedreplicacount > 10) {
println("Bad value for parameter " + param);
exitCode = 1;
System.exit(exitCode);
}
newMetadata.expectedReplicaCount(expectedreplicacount);
break;
case "maxleaderinactivitytime":
int maxleaderinactivitytime = Integer.parseInt(values);
if (maxleaderinactivitytime < 0) {
println("Bad value for parameter " + param);
exitCode = 1;
System.exit(exitCode);
}
newMetadata.maxLeaderInactivityTime(maxleaderinactivitytime);
break;
default:
println("Bad parameter " + param + ", only 'expectedreplicacount' and 'maxleaderinactivitytime' are supported from this interface.");
exitCode = 1;
System.exit(exitCode);
return;
}
boolean ok = clusterManager.updateTableSpace(newMetadata.build(), tableSpace);
if (!ok) {
println("Failed to alter " + schema + " tablespace");
} else {
println("Successfully altered " + schema + " tablespace");
}
}
Aggregations