Java Code Examples for org.apache.cassandra.config.DatabaseDescriptor#getCommitLogSegmentSize()

The following examples show how to use org.apache.cassandra.config.DatabaseDescriptor#getCommitLogSegmentSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommitLogTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static int getMaxRecordDataSize(String keyspace, ByteBuffer key, String table, CellName column)
{
    Mutation rm = new Mutation("Keyspace1", bytes("k"));
    rm.add("Standard1", Util.cellname("c1"), ByteBuffer.allocate(0), 0);

    int max = (DatabaseDescriptor.getCommitLogSegmentSize() / 2);
    max -= CommitLogSegment.ENTRY_OVERHEAD_SIZE; // log entry overhead
    return max - (int) Mutation.serializer.serializedSize(rm, MessagingService.current_version);
}
 
Example 2
Source File: CommitLogSegmentManager.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public CommitLogSegmentManager()
{
    // The run loop for the manager thread
    Runnable runnable = new WrappedRunnable()
    {
        public void runMayThrow() throws Exception
        {
            while (run)
            {
                try
                {
                    Callable<CommitLogSegment> task = segmentManagementTasks.poll();
                    if (task == null)
                    {
                        // if we have no more work to do, check if we should create a new segment
                        if (availableSegments.isEmpty() && (activeSegments.isEmpty() || createReserveSegments))
                        {
                            logger.debug("No segments in reserve; creating a fresh one");
                            size.addAndGet(DatabaseDescriptor.getCommitLogSegmentSize());
                            // TODO : some error handling in case we fail to create a new segment
                            availableSegments.add(CommitLogSegment.freshSegment());
                            hasAvailableSegments.signalAll();
                        }

                        // flush old Cfs if we're full
                        long unused = unusedCapacity();
                        if (unused < 0)
                        {
                            List<CommitLogSegment> segmentsToRecycle = new ArrayList<>();
                            long spaceToReclaim = 0;
                            for (CommitLogSegment segment : activeSegments)
                            {
                                if (segment == allocatingFrom)
                                    break;
                                segmentsToRecycle.add(segment);
                                spaceToReclaim += DatabaseDescriptor.getCommitLogSegmentSize();
                                if (spaceToReclaim + unused >= 0)
                                    break;
                            }
                            flushDataFrom(segmentsToRecycle, false);
                        }

                        try
                        {
                            // wait for new work to be provided
                            task = segmentManagementTasks.take();
                        }
                        catch (InterruptedException e)
                        {
                            throw new AssertionError();
                        }
                    }

                    CommitLogSegment recycled = task.call();
                    if (recycled != null)
                    {
                        // if the work resulted in a segment to recycle, publish it
                        availableSegments.add(recycled);
                        hasAvailableSegments.signalAll();
                    }
                }
                catch (Throwable t)
                {
                    JVMStabilityInspector.inspectThrowable(t);
                    if (!CommitLog.handleCommitError("Failed managing commit log segments", t))
                        return;
                    // sleep some arbitrary period to avoid spamming CL
                    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
                }
            }
        }
    };

    managerThread = new Thread(runnable, "COMMIT-LOG-ALLOCATOR");
    managerThread.start();
}