Beispiel #1
0
  /**
   * Rename a map.
   *
   * @param map the map
   * @param newName the new name
   */
  public synchronized void renameMap(BTreeMap<?, ?> map, String newName) { // TODO
    if (map.isInMemory()) return;
    checkOpen();
    String oldName = map.getName();
    if (oldName.equals(newName)) {
      return;
    }

    String fileName = (String) map.config.get("storageName");
    if (fileName != null) {
      fileName = fileName + File.separator + newName;
      if (!FileUtils.exists(fileName)) FileUtils.createDirectories(fileName);

      close();

      FileUtils.move(btreeStorageName, fileName);
      // btreeStorageName = fileName;
    }
  }
Beispiel #2
0
  /**
   * Create and open the storage.
   *
   * @param map the map to use
   * @throws IllegalStateException if the file is corrupt, or an exception occurred while opening
   * @throws IllegalArgumentException if the directory does not exist
   */
  protected BTreeStorage(BTreeMap<Object, Object> map) {
    this.map = map;
    btreeStorageName = map.getBTreeStorageName();
    Map<String, Object> config = map.config;

    Object value = config.get("retentionTime");
    retentionTime = value == null ? 45000 : (Long) value;

    value = config.get("versionsToKeep");
    versionsToKeep = value == null ? 5 : (Integer) value;

    reuseSpace = config.containsKey("reuseSpace");

    value = config.get("pageSplitSize");
    pageSplitSize = value != null ? (Integer) value : (map.isInMemory() ? 4 * 1024 : 16 * 1024);

    backgroundExceptionHandler =
        (UncaughtExceptionHandler) config.get("backgroundExceptionHandler");

    if (map.isInMemory()) {
      cache = null;
      compressionLevel = 0;
      autoCompactFillRate = 0;
      autoCommitMemory = 0;

      createVersion = 0;
      creationTime = getTimeAbsolute();
      return;
    }

    value = config.get("cacheSize");
    int mb = value == null ? 16 : (Integer) value;
    if (mb > 0) {
      CacheLongKeyLIRS.Config cc = new CacheLongKeyLIRS.Config();
      cc.maxMemory = mb * 1024L * 1024L;
      cache = new CacheLongKeyLIRS<BTreePage>(cc);
    } else {
      cache = null;
    }

    value = config.get("compress");
    compressionLevel = value == null ? 0 : (Integer) value;

    value = config.get("autoCompactFillRate");
    autoCompactFillRate = value == null ? 50 : (Integer) value;

    value = config.get("autoCommitBufferSize");
    int kb = value == null ? 1024 : (Integer) value;
    // 19 KB memory is about 1 KB storage
    autoCommitMemory = kb * 1024 * 19;

    lastChunkId = 0;
    long createVersion = Long.MAX_VALUE;
    if (!FileUtils.exists(btreeStorageName)) FileUtils.createDirectories(btreeStorageName);
    String[] files = new File(btreeStorageName).list();
    if (files != null && files.length > 0) {
      for (String f : files) {
        int id = Integer.parseInt(f.substring(0, f.length() - AOStorage.SUFFIX_AO_FILE_LENGTH));
        if (id > lastChunkId) lastChunkId = id;

        if (id < createVersion) createVersion = id;
      }
    }
    if (createVersion == Long.MAX_VALUE) createVersion = 0;
    this.createVersion = createVersion;

    try {
      if (lastChunkId > 0) readLastChunk();
    } catch (IllegalStateException e) {
      panic(e);
    }

    if (lastChunk != null) creationTime = lastChunk.creationTime;
    else creationTime = getTimeAbsolute();
    lastCommitTime = getTimeSinceCreation();
  }