Example #1
0
  /**
   * param @ table - name of table for which we are maintaining this commit log. param @
   * recoverymode - is commit log being instantiated in in recovery mode.
   */
  private CommitLog() {
    try {
      DatabaseDescriptor.createAllDirectories();
      segmentSize = DatabaseDescriptor.getCommitLogSegmentSize();
    } catch (IOException e) {
      throw new IOError(e);
    }

    // all old segments are recovered and deleted before CommitLog is instantiated.
    // All we need to do is create a new one.
    segments.add(new CommitLogSegment());

    executor =
        DatabaseDescriptor.getCommitLogSync() == Config.CommitLogSync.batch
            ? new BatchCommitLogExecutorService()
            : new PeriodicCommitLogExecutorService(this);
  }
  @VisibleForTesting
  CommitLog(String location, CommitLogArchiver archiver) {
    compressorClass = DatabaseDescriptor.getCommitLogCompression();
    this.location = location;
    ICompressor compressor =
        compressorClass != null ? CompressionParameters.createCompressor(compressorClass) : null;
    DatabaseDescriptor.createAllDirectories();

    this.compressor = compressor;
    this.archiver = archiver;
    metrics = new CommitLogMetrics();

    executor =
        DatabaseDescriptor.getCommitLogSync() == Config.CommitLogSync.batch
            ? new BatchCommitLogService(this)
            : new PeriodicCommitLogService(this);

    allocator = new CommitLogSegmentManager(this);

    // register metrics
    metrics.attach(executor, allocator);
  }
  /**
   * param @ table - name of table for which we are maintaining this commit log. param @
   * recoverymode - is commit log being instantiated in in recovery mode.
   */
  private CommitLog() {
    // all old segments are recovered and deleted before CommitLog is instantiated.
    // All we need to do is create a new one.
    segments.add(new CommitLogSegment());

    if (DatabaseDescriptor.getCommitLogSync() == Config.CommitLogSync.periodic) {
      executor = new PeriodicCommitLogExecutorService();
      final Callable syncer =
          new Callable() {
            public Object call() throws Exception {
              sync();
              return null;
            }
          };

      new Thread(
              new Runnable() {
                public void run() {
                  while (true) {
                    try {
                      executor.submit(syncer).get();
                      Thread.sleep(DatabaseDescriptor.getCommitLogSyncPeriod());
                    } catch (InterruptedException e) {
                      throw new AssertionError(e);
                    } catch (ExecutionException e) {
                      throw new RuntimeException(e);
                    }
                  }
                }
              },
              "PERIODIC-COMMIT-LOG-SYNCER")
          .start();
    } else {
      executor = new BatchCommitLogExecutorService();
    }
  }