use of herddb.metadata.MetadataStorageManagerException in project herddb by diennea.
the class FileMetadataStorageManager method persistTableSpaceOnDisk.
private void persistTableSpaceOnDisk(TableSpace tableSpace) throws MetadataStorageManagerException {
Path tablespaceMetaTmp = baseDirectory.resolve(tableSpace.name.toLowerCase() + "." + System.nanoTime() + ".tmpmetadata");
Path tablespaceMeta = baseDirectory.resolve(tableSpace.name.toLowerCase() + ".metadata");
try (ManagedFile file = ManagedFile.open(tablespaceMetaTmp, ServerConfiguration.PROPERTY_REQUIRE_FSYNC_DEFAULT);
SimpleBufferedOutputStream buffer = new SimpleBufferedOutputStream(file.getOutputStream(), FileDataStorageManager.COPY_BUFFERS_SIZE);
XXHash64Utils.HashingOutputStream oo = new XXHash64Utils.HashingOutputStream(buffer);
ExtendedDataOutputStream dout = new ExtendedDataOutputStream(oo)) {
// version
dout.writeVLong(1);
// flags for future implementations
dout.writeVLong(0);
tableSpace.serialize(dout);
// footer
dout.writeLong(oo.hash());
dout.flush();
file.sync();
} catch (IOException err) {
throw new MetadataStorageManagerException(err);
}
try {
Files.move(tablespaceMetaTmp, tablespaceMeta, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException err) {
throw new MetadataStorageManagerException(err);
}
}
use of herddb.metadata.MetadataStorageManagerException in project herddb by diennea.
the class FileMetadataStorageManager method readTableSpaceMetadataFile.
public static TableSpace readTableSpaceMetadataFile(Path p) throws IOException, MetadataStorageManagerException {
TableSpace ts;
byte[] pageData;
try {
pageData = FileUtils.fastReadFile(p);
} catch (IOException err) {
throw new MetadataStorageManagerException(err);
}
boolean okHash = XXHash64Utils.verifyBlockWithFooter(pageData, 0, pageData.length);
if (!okHash) {
throw new MetadataStorageManagerException("corrutped data file " + p.toAbsolutePath() + ", checksum failed");
}
try (InputStream in = new SimpleByteArrayInputStream(pageData);
ExtendedDataInputStream iin = new ExtendedDataInputStream(in)) {
// version
long version = iin.readVLong();
// flags for future implementations
long flags = iin.readVLong();
if (version != 1 || flags != 0) {
throw new IOException("corrupted data file " + p.toAbsolutePath());
}
ts = TableSpace.deserialize(iin, 0, 0);
}
return ts;
}
use of herddb.metadata.MetadataStorageManagerException in project herddb by diennea.
the class FileMetadataStorageManager method clear.
@Override
public void clear() throws MetadataStorageManagerException {
lock.writeLock().lock();
try {
FileUtils.cleanDirectory(baseDirectory);
Files.createDirectories(baseDirectory);
nodes.clear();
tableSpaces.clear();
} catch (IOException err) {
LOGGER.log(Level.SEVERE, "cannot clear local data", err);
throw new MetadataStorageManagerException(err);
} finally {
lock.writeLock().unlock();
}
}
use of herddb.metadata.MetadataStorageManagerException in project herddb by diennea.
the class ZookeeperMetadataStorageManager method ensureDefaultTableSpace.
@Override
public boolean ensureDefaultTableSpace(String localNodeId, String initialReplicaList, long maxLeaderInactivityTime, int expectedReplicaCount) throws MetadataStorageManagerException {
try {
TableSpaceList list = listTablesSpaces();
if (!list.tableSpaces.contains(TableSpace.DEFAULT)) {
TableSpace tableSpace = TableSpace.builder().leader(localNodeId).replica(initialReplicaList).expectedReplicaCount(1).maxLeaderInactivityTime(maxLeaderInactivityTime).expectedReplicaCount(expectedReplicaCount).name(TableSpace.DEFAULT).build();
createTableSpaceNode(tableSpace);
return true;
} else {
return false;
}
} catch (TableSpaceAlreadyExistsException err) {
// not a problem
return false;
} catch (InterruptedException | KeeperException | IOException err) {
handleSessionExpiredError(err);
throw new MetadataStorageManagerException(err);
}
}
use of herddb.metadata.MetadataStorageManagerException in project herddb by diennea.
the class ZookeeperMetadataStorageManager method listNodes.
@Override
public List<NodeMetadata> listNodes() throws MetadataStorageManagerException {
try {
List<String> children = ensureZooKeeper().getChildren(nodesPath, mainWatcher, null);
List<NodeMetadata> result = new ArrayList<>();
for (String child : children) {
NodeMetadata nodeMetadata = getNode(child);
result.add(nodeMetadata);
}
return result;
} catch (IOException | InterruptedException | KeeperException err) {
handleSessionExpiredError(err);
throw new MetadataStorageManagerException(err);
}
}
Aggregations