Examples of ReusableBuffer


Examples of org.xtreemfs.foundation.buffer.ReusableBuffer

            }
        };
       
        for (int i = 0; i < 100; i++) {
            String pl = "Entry " + (i + 1);
            ReusableBuffer plb = ReusableBuffer.wrap(pl.getBytes());
            l.append(new LogEntry(plb, sl, LogEntry.PAYLOAD_TYPE_INSERT));
        }
        synchronized (count) {
            if (count.get() < 100)
                count.wait(1000);
View Full Code Here

Examples of org.xtreemfs.foundation.buffer.ReusableBuffer

            }
        };
       
        for (int i = 0; i < 100; i++) {
            String pl = "Entry " + (i + 1);
            ReusableBuffer plb = ReusableBuffer.wrap(pl.getBytes());
            LogEntry e = new LogEntry(plb, sl, LogEntry.PAYLOAD_TYPE_INSERT);
            int entrySize = LogEntry.headerLength + e.getPayload().remaining();
           
            if (i < 99)
                offsets[i + 1] = offsets[i] + entrySize;
            else
                totalSize = offsets[offsets.length - 1] + entrySize;
            l.append(e);
        }
        synchronized (count) {
            while (count.get() < 100)
                count.wait(1000);
        }
       
        System.out.println("finished writing");
       
        try {
            l.lock();
            l.switchLogFile(false);
        } finally {
            l.unlock();
        }
       
        assertEquals(totalSize, logFile.length());
       
        File tmpFile = new File(testdir + "log.dbl");
        copyFile(logFile, tmpFile);
       
        // write incorrect data in the first entr...
        RandomAccessFile raf = new RandomAccessFile(tmpFile.getAbsolutePath(), "rw");
        raf.seek(Integer.SIZE / 8);
        raf.writeInt(999999);
        raf.close();
       
        DiskLogFile f = new DiskLogFile(tmpFile.getAbsolutePath());
        assertFalse(f.hasNext());
        f.close();
       
        assertTrue(tmpFile.delete());
        copyFile(logFile, tmpFile);
       
        // write an incorrect size in the first entry...
        raf = new RandomAccessFile(tmpFile.getAbsoluteFile(), "rw");
        raf.writeInt(2);
        raf.close();
       
        f = new DiskLogFile(tmpFile.getAbsolutePath());
        assertFalse(f.hasNext());
        f.close();
       
        assertTrue(tmpFile.delete());
        copyFile(logFile, tmpFile);
       
        // write a corrupted entry in the middle of the log file...
        raf = new RandomAccessFile(tmpFile.getAbsolutePath(), "rw");
        raf.seek(offsets[50]);
        raf.writeInt(79);
        raf.close();
       
        f = new DiskLogFile(tmpFile.getAbsolutePath());
        for (int i = 0; i < 50; i++) {
            LogEntry next = f.next();
            assertNotNull(next);
            next.free();
        }
        assertFalse(f.hasNext());
        f.close();
       
        assertTrue(tmpFile.delete());
        copyFile(logFile, tmpFile);
       
        // write a negative-length entry in the middle of the log file...
        raf = new RandomAccessFile(tmpFile.getAbsolutePath(), "rw");
        raf.seek(offsets[50]);
        raf.writeInt(-122);
        raf.close();
       
        f = new DiskLogFile(tmpFile.getAbsolutePath());
        for (int i = 0; i < 50; i++) {
            LogEntry next = f.next();
            assertNotNull(next);
            next.free();
        }
        assertFalse(f.hasNext());
        f.close();
       
        assertTrue(tmpFile.delete());
        copyFile(logFile, tmpFile);
       
        // write a truncated entry at the end of the log file...
        raf = new RandomAccessFile(tmpFile.getAbsolutePath(), "rw");
        raf.getChannel().truncate(offsets[99] + 5);
        raf.close();
       
        f = new DiskLogFile(tmpFile.getAbsolutePath());
        for (int i = 0; i < 99; i++) {
            LogEntry next = f.next();
            assertNotNull(next);
            next.free();
        }
        assertFalse(f.hasNext());
        f.close();
       
        // replace the old log file with the corrected log file
        logFile.delete();
        copyFile(tmpFile, logFile);
        tmpFile.delete();
       
        // restart the disk logger and append new log entries
        l.shutdown();
        l = new DiskLogger(testdir, new LSN(1, 200L), SyncMode.FSYNC, 0, 0);
        l.start();
       
        for (int i = 99; i < 120; i++) {
            String pl = "Entry " + (i + 1);
            ReusableBuffer plb = ReusableBuffer.wrap(pl.getBytes());
            l.append(new LogEntry(plb, sl, LogEntry.PAYLOAD_TYPE_INSERT));
        }
        synchronized (count) {
            if (count.get() < 121)
                count.wait(1000);
View Full Code Here

Examples of org.xtreemfs.foundation.buffer.ReusableBuffer

                }
            };
           
            for (int i = 0; i < 100; i++) {
                String pl = "Entry " + (k * 100 + i + 1);
                ReusableBuffer plb = ReusableBuffer.wrap(pl.getBytes());
                l.append(new LogEntry(plb, sl, LogEntry.PAYLOAD_TYPE_INSERT));
            }
            synchronized (count) {
                if (count.get() < 100)
                    count.wait();
View Full Code Here

Examples of org.xtreemfs.foundation.buffer.ReusableBuffer

            };
           
            for (int i = 0; i < numEntries; i++) {
               
                String pl = "Entry " + (i + 1);
                ReusableBuffer plb = ReusableBuffer.wrap(pl.getBytes());
                LogEntry e = new LogEntry(plb, sl, LogEntry.PAYLOAD_TYPE_INSERT);
                int entrySize = LogEntry.headerLength + e.getPayload().remaining();
               
                totalSize += entrySize;
                l.append(e);
View Full Code Here

Examples of org.xtreemfs.foundation.buffer.ReusableBuffer

        assertTrue(TransactionInternal.containsOperationType(aggregate, Operation.TYPE_DELETE_DB));
        assertFalse(TransactionInternal.containsOperationType(aggregate, Operation.TYPE_CREATE_SNAP));
       
        // serialize transaction to buffer
        int size = txn.getSize();
        ReusableBuffer buf = BufferPool.allocate(size);
        txn.serialize(buf);
        assertEquals(buf.position(), size);
       
        // deserialize transaction from buffer
        buf.position(0);
        TransactionInternal txn2 = TransactionInternal.deserialize(buf);
        assertEquals(buf.position(), size);
       
        // compare original transaction with deserialized transaction
        assertEquals(txn.getSize(), txn2.getSize());
        assertEquals(txn.getOperations().size(), txn2.getOperations().size());
        for (int i = 0; i < txn.getOperations().size(); i++) {
View Full Code Here

Examples of org.xtreemfs.foundation.buffer.ReusableBuffer

     * @throws BabuDBException if something went wrong.
     */
    public final void makePersistent(TransactionInternal transaction,
            BabuDBRequestResultImpl<Object> requestFuture) throws BabuDBException {
       
        ReusableBuffer buffer = null;
        try {
            buffer = transaction.serialize(
                    BufferPool.allocate(transaction.getSize()));
            buffer.flip();
            makePersistent(transaction, buffer, requestFuture);
        } catch (IOException e) {
            if (buffer != null) BufferPool.free(buffer);
            throw new BabuDBException (ErrorCode.IO_ERROR, e.getMessage(), e);
        }
View Full Code Here

Examples of org.xtreemfs.foundation.buffer.ReusableBuffer

        this.timestamp = timestamp;
        this.replicationOperation = operation;
    }
   
    public void deserializeMessage(Message message) throws IOException {
        final ReusableBuffer payload = rpcRequest.getMessage();
        if (message != null) {
            if (payload != null) {
                ReusableBufferInputStream istream = new ReusableBufferInputStream(payload);
                requestMessage = message.newBuilderForType().mergeFrom(istream).build();
                if (Logging.isDebug()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.