Search in sources :

Example 11 with MetadataStorageManagerException

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);
    }
}
Also used : Path(java.nio.file.Path) MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) SimpleBufferedOutputStream(herddb.utils.SimpleBufferedOutputStream) IOException(java.io.IOException) XXHash64Utils(herddb.utils.XXHash64Utils) ManagedFile(herddb.utils.ManagedFile) ExtendedDataOutputStream(herddb.utils.ExtendedDataOutputStream)

Example 12 with MetadataStorageManagerException

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;
}
Also used : MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) TableSpace(herddb.model.TableSpace) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 13 with MetadataStorageManagerException

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();
    }
}
Also used : MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) IOException(java.io.IOException)

Example 14 with MetadataStorageManagerException

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);
    }
}
Also used : TableSpaceAlreadyExistsException(herddb.model.TableSpaceAlreadyExistsException) MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) TableSpace(herddb.model.TableSpace) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 15 with MetadataStorageManagerException

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);
    }
}
Also used : NodeMetadata(herddb.model.NodeMetadata) MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)35 IOException (java.io.IOException)22 TableSpace (herddb.model.TableSpace)17 ArrayList (java.util.ArrayList)12 KeeperException (org.apache.zookeeper.KeeperException)12 StatementExecutionException (herddb.model.StatementExecutionException)11 DDLException (herddb.model.DDLException)9 NodeMetadata (herddb.model.NodeMetadata)7 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 Record (herddb.model.Record)4 ClientConfiguration (herddb.client.ClientConfiguration)3 HDBConnection (herddb.client.HDBConnection)3 LogNotAvailableException (herddb.log.LogNotAvailableException)3 Table (herddb.model.Table)3 TableSpaceReplicaState (herddb.model.TableSpaceReplicaState)3 SQLPlannedOperationStatement (herddb.model.commands.SQLPlannedOperationStatement)3 ScanStatement (herddb.model.commands.ScanStatement)3 DataStorageManagerException (herddb.storage.DataStorageManagerException)3 Path (java.nio.file.Path)3 ExecutionException (java.util.concurrent.ExecutionException)3