Java Code Examples for io.atomix.storage.StorageLevel#MEMORY

The following examples show how to use io.atomix.storage.StorageLevel#MEMORY . 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: MetaStore.java    From atomix with Apache License 2.0 6 votes vote down vote up
public MetaStore(RaftStorage storage, Serializer serializer) {
  this.serializer = checkNotNull(serializer, "serializer cannot be null");

  if (!(storage.directory().isDirectory() || storage.directory().mkdirs())) {
    throw new IllegalArgumentException(String.format("Can't create storage directory [%s].", storage.directory()));
  }

  // Note that for raft safety, irrespective of the storage level, <term, vote> metadata is always persisted on disk.
  File metaFile = new File(storage.directory(), String.format("%s.meta", storage.prefix()));
  metadataBuffer = FileBuffer.allocate(metaFile, 12);

  if (storage.storageLevel() == StorageLevel.MEMORY) {
    configurationBuffer = HeapBuffer.allocate(32);
  } else {
    File confFile = new File(storage.directory(), String.format("%s.conf", storage.prefix()));
    configurationBuffer = FileBuffer.allocate(confFile, 32);
  }
}
 
Example 2
Source File: RaftServiceManager.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a boolean indicating whether the node is running out of memory.
 */
private boolean isRunningOutOfMemory() {
  StorageLevel level = raft.getStorage().storageLevel();
  if (level == StorageLevel.MEMORY || level == StorageLevel.MAPPED) {
    long freeMemory = raft.getStorage().statistics().getFreeMemory();
    long totalMemory = raft.getStorage().statistics().getTotalMemory();
    if (freeMemory > 0 && totalMemory > 0) {
      return freeMemory / (double) totalMemory < raft.getStorage().freeMemoryBuffer();
    }
  }
  return false;
}
 
Example 3
Source File: SnapshotStore.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Opens the snapshot manager.
 */
private void open() {
  // load persisted snapshots only if storage level is persistent
  if (storage.storageLevel() != StorageLevel.MEMORY) {
    for (Snapshot snapshot : loadSnapshots()) {
      completeSnapshot(snapshot);
    }
  }
}
 
Example 4
Source File: SnapshotStore.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new snapshot.
 *
 * @param index     The snapshot index.
 * @param timestamp The snapshot timestamp.
 * @return The snapshot.
 */
public Snapshot newSnapshot(long index, WallClockTimestamp timestamp) {
  SnapshotDescriptor descriptor = SnapshotDescriptor.builder()
      .withIndex(index)
      .withTimestamp(timestamp.unixTimestamp())
      .build();

  if (storage.storageLevel() == StorageLevel.MEMORY) {
    return createMemorySnapshot(descriptor);
  } else {
    return createDiskSnapshot(descriptor);
  }
}
 
Example 5
Source File: MemoryJournalTest.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
protected StorageLevel storageLevel() {
  return StorageLevel.MEMORY;
}