use of herddb.model.TableSpaceDoesNotExistException in project herddb by diennea.
the class ShowCreateTableCalculator method calculateShowCreateTable.
public static TranslatedQuery calculateShowCreateTable(String query, String defaultTablespace, List<Object> parameters, DBManager manager) {
String[] items = { "SHOW", "CREATE", "TABLE" };
if (Arrays.stream(items).allMatch(query::contains)) {
query = query.substring(Arrays.stream(items).collect(Collectors.joining(" ")).length()).trim();
String tableSpace = defaultTablespace;
String tableName;
boolean showCreateIndex = query.contains("WITH INDEXES");
if (showCreateIndex) {
query = query.substring(0, query.indexOf("WITH INDEXES"));
}
if (query.contains(".")) {
String[] tokens = query.split("\\.");
tableSpace = tokens[0].trim();
tableName = tokens[1].trim();
} else {
tableName = query.trim();
}
tableName = tableName.toLowerCase();
TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(tableSpace);
if (tableSpaceManager == null) {
throw new TableSpaceDoesNotExistException(String.format("Tablespace %s does not exist.", tableSpace));
}
AbstractTableManager tableManager = tableSpaceManager.getTableManager(tableName);
if (tableManager == null || tableManager.getCreatedInTransaction() > 0) {
throw new TableDoesNotExistException(String.format("Table %s does not exist.", tableName));
}
String showCreateResult = calculate(showCreateIndex, tableName, tableSpace, tableManager);
ValuesOp values = new ValuesOp(manager.getNodeId(), new String[] { "tabledef" }, new Column[] { column("tabledef", ColumnTypes.STRING) }, Arrays.asList(Arrays.asList(new ConstantExpression(showCreateResult, ColumnTypes.NOTNULL_STRING))));
ExecutionPlan executionPlan = ExecutionPlan.simple(new SQLPlannedOperationStatement(values), values);
return new TranslatedQuery(executionPlan, new SQLStatementEvaluationContext(query, parameters, false, false));
} else {
throw new StatementExecutionException(String.format("Incorrect Syntax for SHOW CREATE TABLE tablespace.tablename"));
}
}
use of herddb.model.TableSpaceDoesNotExistException in project herddb by diennea.
the class TableSpaceManager method createAndWriteTableCheksum.
// this method return a tableCheckSum object contain scan values (record numbers , table digest,digestType, next autoincrement value, table name, tablespacename, query used for table scan )
public TableChecksum createAndWriteTableCheksum(TableSpaceManager tableSpaceManager, String tableSpaceName, String tableName, StatementEvaluationContext context) throws IOException, DataScannerException {
CommitLogResult pos;
boolean lockAcquired = false;
if (context == null) {
context = StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT();
}
long lockStamp = context.getTableSpaceLock();
LOGGER.log(Level.INFO, "Create and write table {0} checksum in tablespace ", new Object[] { tableName, tableSpaceName });
if (lockStamp == 0) {
lockStamp = acquireWriteLock("checkDataConsistency_" + tableName);
context.setTableSpaceLock(lockStamp);
lockAcquired = true;
}
try {
AbstractTableManager tablemanager = tableSpaceManager.getTableManager(tableName);
if (tableSpaceManager == null) {
throw new TableSpaceDoesNotExistException(String.format("Tablespace %s does not exist.", tableSpaceName));
}
if (tablemanager == null || tablemanager.getCreatedInTransaction() > 0) {
throw new TableDoesNotExistException(String.format("Table %s does not exist.", tablemanager));
}
TableChecksum scanResult = TableDataChecksum.createChecksum(tableSpaceManager.getDbmanager(), null, tableSpaceManager, tableSpaceName, tableName);
byte[] serialize = MAPPER.writeValueAsBytes(scanResult);
Bytes value = Bytes.from_array(serialize);
LogEntry entry = LogEntryFactory.dataConsistency(tableName, value);
pos = log.log(entry, false);
apply(pos, entry, false);
return scanResult;
} finally {
if (lockAcquired) {
releaseWriteLock(context.getTableSpaceLock(), "checkDataConsistency");
context.setTableSpaceLock(0);
}
}
}
use of herddb.model.TableSpaceDoesNotExistException in project herddb by diennea.
the class ZookeeperMetadataStorageManager method updateTableSpaceNode.
private boolean updateTableSpaceNode(TableSpace tableSpace, int metadataStorageVersion) throws KeeperException, InterruptedException, IOException, TableSpaceDoesNotExistException {
try {
ensureZooKeeper().setData(tableSpacesPath + "/" + tableSpace.name.toLowerCase(), tableSpace.serialize(), metadataStorageVersion);
notifyMetadataChanged("updateTableSpaceNode " + tableSpace + " metadataStorageVersion " + metadataStorageVersion);
return true;
} catch (KeeperException.BadVersionException changed) {
return false;
} catch (KeeperException.NoNodeException changed) {
throw new TableSpaceDoesNotExistException(tableSpace.uuid);
}
}
use of herddb.model.TableSpaceDoesNotExistException in project herddb by diennea.
the class ZookeeperMetadataStorageManager method deleteTableSpaceNode.
private boolean deleteTableSpaceNode(String tableSpaceName, int metadataStorageVersion) throws KeeperException, InterruptedException, IOException, TableSpaceDoesNotExistException {
try {
ensureZooKeeper().delete(tableSpacesPath + "/" + tableSpaceName.toLowerCase(), metadataStorageVersion);
notifyMetadataChanged("deleteTableSpaceNode " + tableSpaceName + " metadataStorageVersion " + metadataStorageVersion);
return true;
} catch (KeeperException.BadVersionException changed) {
return false;
} catch (KeeperException.NoNodeException changed) {
throw new TableSpaceDoesNotExistException(tableSpaceName);
}
}
use of herddb.model.TableSpaceDoesNotExistException 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);
}
}
Aggregations