Package org.fusesource.hawtjournal.api.Journal

Examples of org.fusesource.hawtjournal.api.Journal.WriteBatch


        Location location = new Location();
        location.setSize(size);
        location.setType(type);

        WriteCommand write = new WriteCommand(location, data, sync);
        WriteBatch batch = enqueue(write);

        location.setLatch(batch.getLatch());
        if (sync) {
            try {
                batch.getLatch().await();
            } catch (InterruptedException e) {
                throw new InterruptedIOException();
            }
        }
View Full Code Here


            }
        }
    }

    private WriteBatch enqueue(WriteCommand writeRecord) throws IOException {
        WriteBatch currentBatch = null;
        int spinnings = 0;
        int limit = SPIN_RETRIES;
        while (true) {
            if (shutdown) {
                throw new IOException("DataFileAppender Writer Thread Shutdown!");
            }
            if (firstAsyncException.get() != null) {
                throw new IOException(firstAsyncException.get());
            }
            try {
                if (batching.compareAndSet(false, true) && !shutdown) {
                    try {
                        if (nextWriteBatch == null) {
                            DataFile file = journal.getCurrentWriteFile();
                            boolean canBatch = false;
                            currentBatch = new WriteBatch(file, file.getLength());
                            canBatch = currentBatch.canBatch(writeRecord, journal.getMaxWriteBatchSize(), journal.getMaxFileLength());
                            if (!canBatch) {
                                file = journal.rotateWriteFile();
                                currentBatch = new WriteBatch(file, file.getLength());
                            }
                            WriteCommand controlRecord = currentBatch.prepareBatch();
                            currentBatch.appendBatch(writeRecord);
                            if (!writeRecord.isSync()) {
                                journal.getInflightWrites().put(controlRecord.getLocation(), controlRecord);
                                journal.getInflightWrites().put(writeRecord.getLocation(), writeRecord);
                                nextWriteBatch = currentBatch;
                            } else {
View Full Code Here

     */
    private void processBatches() {
        try {
            boolean last = false;
            while (true) {
                WriteBatch wb = batchQueue.take();

                if (shutdown) {
                    last = true;
                }

                if (!wb.isEmpty()) {
                    boolean newOrRotated = lastAppendDataFile != wb.getDataFile();
                    if (newOrRotated) {
                        if (lastAppendRaf != null) {
                            lastAppendRaf.close();
                        }
                        lastAppendDataFile = wb.getDataFile();
                        lastAppendRaf = lastAppendDataFile.openRandomAccessFile();
                    }

                    // perform batch:
                    Location latest = wb.perform(lastAppendRaf, journal.getReplicationTarget(), journal.isChecksum());

                    // Adjust journal length and pointers:
                    journal.addToTotalLength(wb.getSize());
                    journal.setLastAppendLocation(latest);

                    // Now that the data is on disk, remove the writes from the in-flight cache and notify listeners.
                    Collection<WriteCommand> commands = wb.getWrites();
                    for (WriteCommand current : commands) {
                        if (!current.isSync()) {
                            journal.getInflightWrites().remove(current.getLocation());
                        }
                    }
                    if (journal.getListener() != null) {
                        try {
                            journal.getListener().synced(commands.toArray(new WriteCommand[commands.size()]));
                        } catch (Throwable ex) {
                            warn(ex, ex.getMessage());
                        }
                    }

                    // Signal any waiting threads that the write is on disk.
                    wb.getLatch().countDown();
                }

                if (last) {
                    break;
                }
View Full Code Here

TOP

Related Classes of org.fusesource.hawtjournal.api.Journal.WriteBatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.