Example #1
0
  /*
   * @SuppressWarnings is used to stifle a type safety complaint about the
   * assignment of lockTables = new Map[nLockTables]. There's no way to
   * specify the type of the array.
   */
  @SuppressWarnings("unchecked")
  public LockManager(EnvironmentImpl envImpl) {

    DbConfigManager configMgr = envImpl.getConfigManager();
    nLockTables = configMgr.getInt(EnvironmentParams.N_LOCK_TABLES);
    oldLockExceptions = configMgr.getBoolean(EnvironmentParams.LOCK_OLD_LOCK_EXCEPTIONS);
    lockTables = new Map[nLockTables];
    lockTableLatches = new Latch[nLockTables];
    for (int i = 0; i < nLockTables; i++) {
      lockTables[i] = new HashMap<Long, Lock>();
      lockTableLatches[i] = new Latch("Lock Table " + i);
    }
    this.envImpl = envImpl;
    memoryBudget = envImpl.getMemoryBudget();

    stats = new StatGroup(GROUP_NAME, GROUP_DESC);
    nRequests = new LongStat(stats, LOCK_REQUESTS);
    nWaits = new LongStat(stats, LOCK_WAITS);

    /* Initialize mutable properties and register for notifications. */
    envConfigUpdate(configMgr, null);
    envImpl.addConfigObserver(this);

    if (envImpl.isReplicated()) {
      threadLockers = new ConcurrentHashMap<Thread, TinyHashSet<ThreadLocker>>();
    } else {
      threadLockers = null;
    }
  }
  /**
   * Figure out the wakeup period. Supplied through this static method because we need to pass
   * wakeup period to the superclass and need to do the calcuation outside this constructor.
   */
  public static long getWakeupPeriod(DbConfigManager configManager)
      throws IllegalArgumentException, DatabaseException {

    long wakeupPeriod =
        PropUtil.microsToMillis(
            configManager.getLong(EnvironmentParams.CHECKPOINTER_WAKEUP_INTERVAL));
    long bytePeriod = configManager.getLong(EnvironmentParams.CHECKPOINTER_BYTES_INTERVAL);

    /* Checkpointing period must be set either by time or by log size. */
    if ((wakeupPeriod == 0) && (bytePeriod == 0)) {
      throw new IllegalArgumentException(
          EnvironmentParams.CHECKPOINTER_BYTES_INTERVAL.getName()
              + " and "
              + EnvironmentParams.CHECKPOINTER_WAKEUP_INTERVAL.getName()
              + " cannot both be 0. ");
    }

    /*
     * Checkpointing by log size takes precendence over time based period
     */
    if (bytePeriod == 0) {
      return wakeupPeriod;
    } else {
      return 0;
    }
  }
    protected ReadWindow(int readBufferSize, EnvironmentImpl envImpl) {
      DbConfigManager configManager = envImpl.getConfigManager();
      maxReadBufferSize = configManager.getInt(EnvironmentParams.LOG_ITERATOR_MAX_SIZE);
      this.envImpl = envImpl;
      fileManager = envImpl.getFileManager();

      readBuffer = ByteBuffer.allocate(readBufferSize);
      threadSafeBufferFlip(readBuffer);
    }
  /* Test mutable and persistent configurations. */
  @Test
  public void testPersistentAndMutableConfigs() throws Exception {

    final String dbName = "foo";

    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(true);
    env = create(envHome, envConfig);

    DbConfigManager configMgr = DbInternal.getEnvironmentImpl(env).getConfigManager();
    int defaultNodeMaxEntries = configMgr.getInt(EnvironmentParams.NODE_MAX);
    int defaultNodeDupTreeMaxEntries = configMgr.getInt(EnvironmentParams.NODE_MAX_DUPTREE);

    /* Check the default node max entries setting. */
    assertEquals(defaultNodeMaxEntries, 128);
    assertEquals(defaultNodeDupTreeMaxEntries, 128);

    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    dbConfig.setTransactional(true);

    /* Do updates on each persistent and mutable config. */

    /* Check whether BtreeComparator setting is persisted. */
    dbConfig.setOverrideBtreeComparator(true);
    dbConfig.setBtreeComparator(TestComparator.class);
    DatabaseConfig newConfig = setAndGetDbConfig(env, dbConfig, dbName);
    assertTrue(newConfig.getBtreeComparator() instanceof TestComparator);

    /* Check whether DuplicateComparator setting is persisted. */
    dbConfig.setOverrideDuplicateComparator(true);
    dbConfig.setDuplicateComparator(new TestSerialComparator());
    newConfig = setAndGetDbConfig(env, dbConfig, dbName);
    assertTrue(newConfig.getDuplicateComparator() instanceof TestSerialComparator);

    /* Check whether KeyPrefixing setting is persisted. */
    dbConfig.setKeyPrefixing(true);
    newConfig = setAndGetDbConfig(env, dbConfig, dbName);
    assertTrue(newConfig.getKeyPrefixing());

    /* Check whether NodeMaxEntries setting is persisted. */
    dbConfig.setNodeMaxEntries(512);
    newConfig = setAndGetDbConfig(env, dbConfig, dbName);
    assertTrue(newConfig.getNodeMaxEntries() == 512);

    close(env);
  }
  /** Used by EnvironmentConfig to construct from properties. */
  EnvironmentMutableConfig(Properties properties) throws IllegalArgumentException {

    DbConfigManager.validateProperties(
        properties,
        false, // isRepConfigInstance
        getClass().getName());
    /* For safety, copy the passed in properties. */
    props = new Properties();
    props.putAll(properties);
  }
  /** @hidden The void return setter for use by Bean editors. */
  public void setDurabilityVoid(Durability durability) {
    TransactionConfig.checkMixedMode(false, txnNoSync, txnWriteNoSync, durability);

    if (durability == null) {
      props.remove(EnvironmentParams.JE_DURABILITY);
    } else {
      DbConfigManager.setVal(
          props, EnvironmentParams.JE_DURABILITY, durability.toString(), validateParams);
    }
  }
  /**
   * Set this configuration parameter with this value in the specified Properties object, which is
   * assumed to represent the properties that are applicable to this class. Values are validated
   * before setting the parameter.
   *
   * @param props the Properties object to update
   * @param paramName the configuration parameter name, one of the String constants in this class
   * @param value the configuration value.
   * @throws IllegalArgumentException if the paramName or value is invalid
   */
  private static void setConfigParam(
      Properties props, String paramName, String value, boolean validateParams)
      throws IllegalArgumentException {

    DbConfigManager.setConfigParam(
        props,
        paramName,
        value,
        false, /* require mutability. */
        validateParams,
        true, /* forReplication */
        false); /* verifyForReplication */
  }
  /**
   * Creates an ReplicationNetworkConfig which includes the properties specified in the properties
   * parameter.
   *
   * @param properties Supported properties are described as the string constants in this class.
   * @return an instance of a class derived from ReplicationNetworkConfig as indicated by the
   *     channelType property.
   * @throws IllegalArgumentException If any properties read from the properties parameter are
   *     invalid.
   */
  public static ReplicationNetworkConfig create(Properties properties)
      throws IllegalArgumentException {

    final String channelType = DbConfigManager.getVal(properties, RepParams.CHANNEL_TYPE);

    if ("basic".equals(channelType)) {
      return new ReplicationBasicConfig(properties);
    }
    if ("ssl".equals(channelType)) {
      return new ReplicationSSLConfig(properties);
    }
    throw new IllegalArgumentException("Unknown channel type: " + channelType);
  }
  /**
   * Set this configuration parameter. First validate the value specified for the configuration
   * parameter; if it is valid, the value is set in the configuration.
   *
   * @param paramName the configuration parameter name, one of the String constants in this class
   * @param value The configuration value
   * @return this
   * @throws IllegalArgumentException if the paramName or value is invalid.
   */
  public EnvironmentMutableConfig setConfigParam(String paramName, String value)
      throws IllegalArgumentException {

    DbConfigManager.setConfigParam(
        props,
        paramName,
        value,
        true, /* require mutability. */
        validateParams,
        false /* forReplication */,
        true /* verifyForReplication */);
    return this;
  }
 /**
  * Get the channel logging name setting for the replication service.
  *
  * @return the channel logging name
  */
 public String getLogName() {
   return DbConfigManager.getVal(props, RepParams.CHANNEL_LOG_NAME);
 }
 /**
  * Returns the durability associated with the configuration.
  *
  * @return the durability setting currently associated with this config.
  */
 public Durability getDurability() {
   String value = DbConfigManager.getVal(props, EnvironmentParams.JE_DURABILITY);
   return Durability.parse(value);
 }
Example #12
0
 /** Process notifications of mutable property changes. */
 public void envConfigUpdate(DbConfigManager configMgr, EnvironmentMutableConfig ignore) {
   LockInfo.setDeadlockStackTrace(
       configMgr.getBoolean(EnvironmentParams.TXN_DEADLOCK_STACK_TRACE));
   setLockTableDump(configMgr.getBoolean(EnvironmentParams.TXN_DUMPLOCKS));
 }
  /** @hidden The void return setter for use by Bean editors. */
  public void setCachePercentVoid(int percent) throws IllegalArgumentException {

    DbConfigManager.setIntVal(props, EnvironmentParams.MAX_MEMORY_PERCENT, percent, validateParams);
  }
  /**
   * Returns the percentage value used in the JE cache size calculation.
   *
   * @return the percentage value used in the JE cache size calculation.
   */
  public int getCachePercent() {

    return DbConfigManager.getIntVal(props, EnvironmentParams.MAX_MEMORY_PERCENT);
  }
  /** @hidden The void return setter for use by Bean editors. */
  public void setChannelFactoryParamsVoid(String factoryParams) {

    DbConfigManager.setVal(props, RepParams.CHANNEL_FACTORY_PARAMS, factoryParams, validateParams);
  }
  /**
   * @hidden Returns the DataChannelFactory class parameters to be used for when instantiating the
   *     DataChannelFactoryClass
   * @return the parameters argument, if configured
   */
  public String getChannelFactoryParams() {

    return DbConfigManager.getVal(props, RepParams.CHANNEL_FACTORY_PARAMS);
  }
  /** @hidden The void return setter for use by Bean editors. */
  public void setLogNameVoid(String logName) throws IllegalArgumentException {

    DbConfigManager.setVal(props, RepParams.CHANNEL_LOG_NAME, logName, validateParams);
  }
  /**
   * Returns the value for this configuration parameter.
   *
   * @param paramName a valid configuration parameter, one of the String constants in this class.
   * @return the configuration value.
   * @throws IllegalArgumentException if the paramName is invalid.
   */
  public String getConfigParam(String paramName) throws IllegalArgumentException {

    return DbConfigManager.getConfigParam(props, paramName);
  }
  /** @hidden The void return setter for use by Bean editors. */
  public void setOffHeapCacheSizeVoid(long totalBytes) throws IllegalArgumentException {

    DbConfigManager.setVal(
        props, EnvironmentParams.MAX_OFF_HEAP_MEMORY, Long.toString(totalBytes), validateParams);
  }