use of herddb.client.HDBException 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.client.HDBException in project herddb by diennea.
the class HerdDBPreparedStatement method executeQuery.
@Override
public ResultSet executeQuery() throws SQLException {
try {
parent.discoverTableSpace(sql);
ScanResultSet scanResult = this.parent.getConnection().executeScan(parent.getTableSpace(), sql, true, parameters, parent.ensureTransaction(), maxRows, fetchSize, parent.isKeepReadLocks());
this.parent.bindToTransaction(scanResult.transactionId);
return lastResultSet = new HerdDBResultSet(scanResult, this);
} catch (ClientSideMetadataProviderException | HDBException | InterruptedException ex) {
throw SQLExceptionUtils.wrapException(ex);
}
}
use of herddb.client.HDBException in project herddb by diennea.
the class HerdDBPreparedStatement method executeBatch.
@Override
public int[] executeBatch() throws SQLException {
try {
int[] results = new int[batch.size()];
int i = 0;
lastUpdateCount = 0;
parent.discoverTableSpace(sql);
List<DMLResult> dmlresults = parent.getConnection().executeUpdates(parent.getTableSpace(), sql, parent.ensureTransaction(), false, true, this.batch);
for (DMLResult dmlresult : dmlresults) {
results[i++] = (int) dmlresult.updateCount;
parent.bindToTransaction(dmlresult.transactionId);
lastUpdateCount += dmlresult.updateCount;
lastKey = dmlresult.key;
}
return results;
} catch (ClientSideMetadataProviderException | HDBException err) {
throw SQLExceptionUtils.wrapException(err);
} finally {
batch.clear();
}
}
use of herddb.client.HDBException in project herddb by diennea.
the class HerdDBStatement method executeQuery.
@Override
public ResultSet executeQuery(String sql) throws SQLException {
try {
parent.discoverTableSpace(sql);
ScanResultSet scanResult = this.parent.getConnection().executeScan(parent.getTableSpace(), sql, false, Collections.emptyList(), parent.ensureTransaction(), maxRows, fetchSize, parent.isKeepReadLocks());
parent.bindToTransaction(scanResult.transactionId);
return lastResultSet = new HerdDBResultSet(scanResult, this);
} catch (ClientSideMetadataProviderException | HDBException | InterruptedException ex) {
throw SQLExceptionUtils.wrapException(ex);
}
}
Aggregations