Search in sources :

Example 1 with ODirectFileOutputStream

use of herddb.utils.ODirectFileOutputStream in project herddb by diennea.

the class FileDataStorageManager method writeIndexPage.

@Override
public void writeIndexPage(String tableSpace, String indexName, long pageId, DataWriter writer) throws DataStorageManagerException {
    long _start = System.currentTimeMillis();
    Path tableDir = getIndexDirectory(tableSpace, indexName);
    Path pageFile = getPageFile(tableDir, pageId);
    long size;
    try {
        if (indexodirect) {
            try (ODirectFileOutputStream odirect = new ODirectFileOutputStream(pageFile, O_DIRECT_BLOCK_BATCH, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
                size = writeIndexPage(writer, null, odirect);
            }
        } else {
            try (ManagedFile file = ManagedFile.open(pageFile, requirefsync, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
                SimpleBufferedOutputStream buffer = new SimpleBufferedOutputStream(file.getOutputStream(), COPY_BUFFERS_SIZE)) {
                size = writeIndexPage(writer, file, buffer);
            }
        }
    } catch (IOException err) {
        LOGGER.log(Level.SEVERE, "Failed to write on path: {0}", pageFile);
        Path path = pageFile;
        boolean exists;
        do {
            exists = Files.exists(path);
            if (exists) {
                LOGGER.log(Level.INFO, "Path {0}: directory {1}, file {2}, link {3}, writable {4}, readable {5}, executable {6}", new Object[] { path, Files.isDirectory(path), Files.isRegularFile(path), Files.isSymbolicLink(path), Files.isWritable(path), Files.isReadable(path), Files.isExecutable(path) });
            } else {
                LOGGER.log(Level.INFO, "Path {0} doesn't exists", path);
            }
            path = path.getParent();
        } while (path != null && !exists);
        throw new DataStorageManagerException(err);
    }
    long now = System.currentTimeMillis();
    long delta = (now - _start);
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.log(Level.FINER, "writePage {0} KBytes, time {2} ms", new Object[] { (size / 1024) + "", delta + "" });
    }
    indexPageWrites.registerSuccessfulEvent(delta, TimeUnit.MILLISECONDS);
}
Also used : Path(java.nio.file.Path) SimpleBufferedOutputStream(herddb.utils.SimpleBufferedOutputStream) ODirectFileOutputStream(herddb.utils.ODirectFileOutputStream) DataStorageManagerException(herddb.storage.DataStorageManagerException) IOException(java.io.IOException) ManagedFile(herddb.utils.ManagedFile)

Example 2 with ODirectFileOutputStream

use of herddb.utils.ODirectFileOutputStream in project herddb by diennea.

the class FileDataStorageManager method writePage.

@Override
public void writePage(String tableSpace, String tableName, long pageId, Collection<Record> newPage) throws DataStorageManagerException {
    // synch on table is done by the TableManager
    long _start = System.currentTimeMillis();
    Path tableDir = getTableDirectory(tableSpace, tableName);
    Path pageFile = getPageFile(tableDir, pageId);
    long size;
    try {
        if (pageodirect) {
            try (ODirectFileOutputStream odirect = new ODirectFileOutputStream(pageFile, O_DIRECT_BLOCK_BATCH, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
                size = writePage(newPage, null, odirect);
            }
        } else {
            try (ManagedFile file = ManagedFile.open(pageFile, requirefsync, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
                SimpleBufferedOutputStream buffer = new SimpleBufferedOutputStream(file.getOutputStream(), COPY_BUFFERS_SIZE)) {
                size = writePage(newPage, file, buffer);
            }
        }
    } catch (IOException err) {
        throw new DataStorageManagerException(err);
    }
    long now = System.currentTimeMillis();
    long delta = (now - _start);
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.log(Level.FINER, "writePage {0} KBytes,{1} records, time {2} ms", new Object[] { (size / 1024) + "", newPage.size(), delta + "" });
    }
    dataPageWrites.registerSuccessfulEvent(delta, TimeUnit.MILLISECONDS);
}
Also used : Path(java.nio.file.Path) SimpleBufferedOutputStream(herddb.utils.SimpleBufferedOutputStream) ODirectFileOutputStream(herddb.utils.ODirectFileOutputStream) DataStorageManagerException(herddb.storage.DataStorageManagerException) IOException(java.io.IOException) ManagedFile(herddb.utils.ManagedFile)

Aggregations

DataStorageManagerException (herddb.storage.DataStorageManagerException)2 ManagedFile (herddb.utils.ManagedFile)2 ODirectFileOutputStream (herddb.utils.ODirectFileOutputStream)2 SimpleBufferedOutputStream (herddb.utils.SimpleBufferedOutputStream)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2