Ejemplo n.º 1
0
 public ByteStoreBDB(File dir, String dbname, boolean ro) {
   this.dir = Files.initDirectory(dir);
   this.readonly = ro;
   settings = new SettingsJE();
   EnvironmentConfig bdb_eco = new EnvironmentConfig();
   bdb_eco.setReadOnly(ro);
   bdb_eco.setAllowCreate(!ro);
   bdb_eco.setTransactional(false);
   //          bdb_eco.setDurability(Durability.COMMIT_NO_SYNC);
   if (ro) {
     bdb_eco.setConfigParam(
         EnvironmentConfig.ENV_RUN_CLEANER, "false"); // Disable log cleaner thread
     bdb_eco.setCacheMode(CacheMode.EVICT_LN);
   }
   JEUtil.mergeSystemProperties(bdb_eco);
   SettingsJE.updateEnvironmentConfig(settings, bdb_eco);
   bdb_env = new Environment(dir, bdb_eco);
   bdb_cfg = new DatabaseConfig();
   bdb_cfg.setReadOnly(ro);
   bdb_cfg.setAllowCreate(true);
   bdb_cfg.setDeferredWrite(true);
   SettingsJE.updateDatabaseConfig(settings, bdb_cfg);
   bdb = bdb_env.openDatabase(null, dbname, bdb_cfg);
   if (log.isDebugEnabled()) {
     log.debug(SettingsJE.dumpDebug(bdb));
   }
 }
Ejemplo n.º 2
0
  public BerkeleyStorage(File file, boolean readonly, boolean async) {
    if (file == null) {
      int pid = 0;
      try {
        pid = Integer.parseInt((new File("/proc/self")).getCanonicalFile().getName());
      } catch (NumberFormatException | IOException e) {
      }
      String path = "/tmp";
      String db_path = System.getenv("DB");
      if (db_path != null) {
        path = db_path;
      }
      file = new File(path + "/ringpaxos-db/" + pid);
      file.mkdirs();
    }
    EnvironmentConfig envConfig = new EnvironmentConfig();
    DatabaseConfig dbConfig = new DatabaseConfig();
    envConfig.setReadOnly(readonly);
    dbConfig.setReadOnly(readonly);
    envConfig.setAllowCreate(!readonly);
    dbConfig.setAllowCreate(!readonly);

    // performance settings
    envConfig.setTransactional(true);
    envConfig.setCacheMode(CacheMode.DEFAULT);
    // envConfig.setCacheSize(1000000*800); // 800M
    if (async) {
      dbConfig.setTransactional(false);
      envConfig.setDurability(Durability.COMMIT_NO_SYNC);
      dbConfig.setDeferredWrite(true);
    } else {
      dbConfig.setTransactional(true);
      envConfig.setDurability(Durability.COMMIT_SYNC);
      dbConfig.setDeferredWrite(false);
    }

    env = new Environment(file, envConfig);
    db = env.openDatabase(null, "paxosDB", dbConfig);
    classCatalogDb = env.openDatabase(null, "ClassCatalogDB", dbConfig);
    classCatalog = new StoredClassCatalog(classCatalogDb);
    keyBinding = TupleBinding.getPrimitiveBinding(Long.class);
    dataBinding = new SerialBinding<Decision>(classCatalog, Decision.class);
    ballotBinding = TupleBinding.getPrimitiveBinding(Integer.class);

    logger.info("BerkeleyStorage cache size: " + env.getMutableConfig().getCacheSize());
    logger.info(
        "BerkeleyStorage durability: " + env.getMutableConfig().getDurability().getLocalSync());
    logger.info("BerkeleyStorage deferred write: " + db.getConfig().getDeferredWrite());
  }