Examples of BufferedRandomAccessFile


Examples of org.apache.cassandra.io.BufferedRandomAccessFile

        return Long.parseLong(entries[entries.length - 2]);
    }

    private static BufferedRandomAccessFile createWriter(String file) throws IOException
    {       
        return new BufferedRandomAccessFile(file, "rw");
    }
View Full Code Here

Examples of org.apache.cassandra.io.BufferedRandomAccessFile

        DataInputBuffer bufIn = new DataInputBuffer();
        for (File file : clogs)
        {
            int bufferSize = (int)Math.min(file.length(), 32 * 1024 * 1024);
            BufferedRandomAccessFile reader = new BufferedRandomAccessFile(file.getAbsolutePath(), "r", bufferSize);
            final CommitLogHeader clHeader = readCommitLogHeader(reader);
            /* seek to the lowest position where any CF has non-flushed data */
            int lowPos = CommitLogHeader.getLowestPosition(clHeader);
            if (lowPos == 0)
                break;

            reader.seek(lowPos);
            if (logger_.isDebugEnabled())
                logger_.debug("Replaying " + file + " starting at " + lowPos);

            /* read the logs populate RowMutation and apply */
            while (!reader.isEOF())
            {
                if (logger_.isDebugEnabled())
                    logger_.debug("Reading mutation at " + reader.getFilePointer());

                long claimedCRC32;
                byte[] bytes;
                try
                {
                    bytes = new byte[(int) reader.readLong()]; // readlong can throw EOFException too
                    reader.readFully(bytes);
                    claimedCRC32 = reader.readLong();
                }
                catch (EOFException e)
                {
                    // last CL entry didn't get completely written.  that's ok.
                    break;
                }
                bufIn.reset(bytes, bytes.length);
                Checksum checksum = new CRC32();
                checksum.update(bytes, 0, bytes.length);
                if (claimedCRC32 != checksum.getValue())
                {
                    // this part of the log must not have been fsynced.  probably the rest is bad too,
                    // but just in case there is no harm in trying them.
                    continue;
                }

                /* deserialize the commit log entry */
                final RowMutation rm = RowMutation.serializer().deserialize(bufIn);
                if (logger_.isDebugEnabled())
                    logger_.debug(String.format("replaying mutation for %s.%s: %s",
                                                rm.getTable(),
                                                rm.key(),
                                                "{" + StringUtils.join(rm.getColumnFamilies(), ", ") + "}"));
                final Table table = Table.open(rm.getTable());
                tablesRecovered.add(table);
                final Collection<ColumnFamily> columnFamilies = new ArrayList<ColumnFamily>(rm.getColumnFamilies());
                final long entryLocation = reader.getFilePointer();
                Runnable runnable = new Runnable()
                {
                    public void run()
                    {
                        /* remove column families that have already been flushed before applying the rest */
                        for (ColumnFamily columnFamily : columnFamilies)
                        {
                            int id = table.getColumnFamilyId(columnFamily.name());
                            if (!clHeader.isDirty(id) || entryLocation < clHeader.getPosition(id))
                            {
                                rm.removeColumnFamily(columnFamily);
                            }
                        }
                        if (!rm.isEmpty())
                        {
                            try
                            {
                                Table.open(rm.getTable()).apply(rm, null, false);
                            }
                            catch (IOException e)
                            {
                                throw new IOError(e);
                            }
                        }
                    }
                };
                StageManager.getStage(StageManager.mutationStage_).execute(runnable);
                rows++;
            }
            reader.close();
        }

        // wait for all the writes to finish on the mutation stage
        while (StageManager.getStage(StageManager.mutationStage_).getCompletedTasks() < rows)
        {
View Full Code Here

Examples of org.apache.cassandra.io.BufferedRandomAccessFile

        }
    }

    private void writeOldCommitLogHeader(String oldFile, CommitLogHeader header) throws IOException
    {
        BufferedRandomAccessFile logWriter = CommitLog.createWriter(oldFile);
        writeCommitLogHeader(logWriter, header.toByteArray());
        logWriter.close();
    }
View Full Code Here

Examples of org.apache.cassandra.io.BufferedRandomAccessFile

            cfStore.doCompaction(2, cfStore.getSSTables().size());
        }
        SSTableReader sstable = cfStore.getSSTables().iterator().next();
        DecoratedKey decKey = sstable.getPartitioner().decorateKey(key);
        long position = sstable.getPosition(decKey);
        BufferedRandomAccessFile file = new BufferedRandomAccessFile(sstable.getFilename(), "r");
        file.seek(position);
        assert file.readUTF().equals(key);
        file.readInt();
        IndexHelper.skipBloomFilter(file);
        ArrayList<IndexHelper.IndexInfo> indexes = IndexHelper.deserializeIndex(file);
        assert indexes.size() > 2;
        validateSliceLarge(cfStore);
    }
View Full Code Here

Examples of org.apache.cassandra.io.BufferedRandomAccessFile

        return Long.parseLong(entries[entries.length - 2]);
    }

    private static BufferedRandomAccessFile createWriter(String file) throws IOException
    {       
        return new BufferedRandomAccessFile(file, "rw");
    }
View Full Code Here

Examples of org.apache.cassandra.io.BufferedRandomAccessFile

        DataInputBuffer bufIn = new DataInputBuffer();
        for (File file : clogs)
        {
            int bufferSize = (int)Math.min(file.length(), 32 * 1024 * 1024);
            BufferedRandomAccessFile reader = new BufferedRandomAccessFile(file.getAbsolutePath(), "r", bufferSize);
            final CommitLogHeader clHeader = readCommitLogHeader(reader);
            /* seek to the lowest position where any CF has non-flushed data */
            int lowPos = CommitLogHeader.getLowestPosition(clHeader);
            if (lowPos == 0)
                break;

            reader.seek(lowPos);
            if (logger_.isDebugEnabled())
                logger_.debug("Replaying " + file + " starting at " + lowPos);

            /* read the logs populate RowMutation and apply */
            while (!reader.isEOF())
            {
                if (logger_.isDebugEnabled())
                    logger_.debug("Reading mutation at " + reader.getFilePointer());

                long claimedCRC32;
                byte[] bytes;
                try
                {
                    bytes = new byte[(int) reader.readLong()]; // readlong can throw EOFException too
                    reader.readFully(bytes);
                    claimedCRC32 = reader.readLong();
                }
                catch (EOFException e)
                {
                    // last CL entry didn't get completely written.  that's ok.
                    break;
                }
                bufIn.reset(bytes, bytes.length);
                Checksum checksum = new CRC32();
                checksum.update(bytes, 0, bytes.length);
                if (claimedCRC32 != checksum.getValue())
                {
                    // this part of the log must not have been fsynced.  probably the rest is bad too,
                    // but just in case there is no harm in trying them.
                    continue;
                }

                /* deserialize the commit log entry */
                final RowMutation rm = RowMutation.serializer().deserialize(bufIn);
                if (logger_.isDebugEnabled())
                    logger_.debug(String.format("replaying mutation for %s.%s: %s",
                                                rm.getTable(),
                                                rm.key(),
                                                "{" + StringUtils.join(rm.getColumnFamilies(), ", ") + "}"));
                final Table table = Table.open(rm.getTable());
                tablesRecovered.add(table);
                final Collection<ColumnFamily> columnFamilies = new ArrayList<ColumnFamily>(rm.getColumnFamilies());
                final long entryLocation = reader.getFilePointer();
                Runnable runnable = new Runnable()
                {
                    public void run()
                    {
                        /* remove column families that have already been flushed before applying the rest */
                        for (ColumnFamily columnFamily : columnFamilies)
                        {
                            int id = table.getColumnFamilyId(columnFamily.name());
                            if (!clHeader.isDirty(id) || entryLocation < clHeader.getPosition(id))
                            {
                                rm.removeColumnFamily(columnFamily);
                            }
                        }
                        if (!rm.isEmpty())
                        {
                            try
                            {
                                Table.open(rm.getTable()).apply(rm, null, false);
                            }
                            catch (IOException e)
                            {
                                throw new IOError(e);
                            }
                        }
                    }
                };
                StageManager.getStage(StageManager.mutationStage_).execute(runnable);
                rows++;
            }
            reader.close();
        }

        // wait for all the writes to finish on the mutation stage
        while (StageManager.getStage(StageManager.mutationStage_).getCompletedTasks() < rows)
        {
View Full Code Here

Examples of org.apache.cassandra.io.BufferedRandomAccessFile

        }
    }

    private void writeOldCommitLogHeader(String oldFile, CommitLogHeader header) throws IOException
    {
        BufferedRandomAccessFile logWriter = CommitLog.createWriter(oldFile);
        writeCommitLogHeader(logWriter, header.toByteArray());
        logWriter.close();
    }
View Full Code Here

Examples of org.apache.cassandra.io.BufferedRandomAccessFile

        }
    }
   
    private static void doCheck() throws Throwable
    {
        BufferedRandomAccessFile fis = new BufferedRandomAccessFile("C:\\Engagements\\buff.dat", "r", 4*1024*1024);
        IndexHelper.skipBloomFilterAndIndex(fis);
        byte[] bytes = new byte[(int)(fis.length() - fis.getFilePointer())];
        fis.readFully(bytes);
        DataInputBuffer bufIn = new DataInputBuffer();
        bufIn.reset(bytes, bytes.length);
       
        ColumnFamily cf = ColumnFamily.serializer().deserialize(bufIn);       
        Collection<IColumn> columns = cf.getAllColumns();      
        System.out.println(columns.size());
        for ( IColumn column : columns )
        {
            System.out.println(column.name());
        }
        fis.close();
    }
View Full Code Here

Examples of org.apache.cassandra.io.BufferedRandomAccessFile

            cfStore.doCompaction(2, cfStore.getSSTables().size());
        }
        SSTableReader sstable = cfStore.getSSTables().iterator().next();
        DecoratedKey decKey = sstable.getPartitioner().decorateKey(key);
        long position = sstable.getPosition(decKey);
        BufferedRandomAccessFile file = new BufferedRandomAccessFile(sstable.getFilename(), "r");
        file.seek(position);
        assert file.readUTF().equals(key);
        file.readInt();
        IndexHelper.skipBloomFilter(file);
        ArrayList<IndexHelper.IndexInfo> indexes = IndexHelper.deserializeIndex(file);
        assert indexes.size() > 2;
        validateSliceLarge(cfStore);
    }
View Full Code Here

Examples of org.apache.cassandra.io.BufferedRandomAccessFile

        return Long.parseLong(entries[entries.length - 2]);
    }

    private static BufferedRandomAccessFile createWriter(String file) throws IOException
    {       
        return new BufferedRandomAccessFile(file, "rw");
    }
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.