HDDS-2269. Provide config for fair/non-fair for OM RW Lock. (#1623)
This commit is contained in:
parent
effe6087a5
commit
4850b3aa86
|
@ -453,6 +453,9 @@ public final class OzoneConfigKeys {
|
||||||
"ozone.network.topology.aware.read";
|
"ozone.network.topology.aware.read";
|
||||||
public static final boolean OZONE_NETWORK_TOPOLOGY_AWARE_READ_DEFAULT = false;
|
public static final boolean OZONE_NETWORK_TOPOLOGY_AWARE_READ_DEFAULT = false;
|
||||||
|
|
||||||
|
public static final String OZONE_MANAGER_FAIR_LOCK = "ozone.om.lock.fair";
|
||||||
|
public static final boolean OZONE_MANAGER_FAIR_LOCK_DEFAULT = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There is no need to instantiate this class.
|
* There is no need to instantiate this class.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -31,9 +31,12 @@ public final class ActiveLock {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use ActiveLock#newInstance to create instance.
|
* Use ActiveLock#newInstance to create instance.
|
||||||
|
*
|
||||||
|
* @param fairness - if true the lock uses a fair ordering policy, else
|
||||||
|
* non-fair ordering.
|
||||||
*/
|
*/
|
||||||
private ActiveLock() {
|
private ActiveLock(boolean fairness) {
|
||||||
this.lock = new ReentrantReadWriteLock();
|
this.lock = new ReentrantReadWriteLock(fairness);
|
||||||
this.count = new AtomicInteger(0);
|
this.count = new AtomicInteger(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +45,8 @@ public final class ActiveLock {
|
||||||
*
|
*
|
||||||
* @return new ActiveLock
|
* @return new ActiveLock
|
||||||
*/
|
*/
|
||||||
public static ActiveLock newInstance() {
|
public static ActiveLock newInstance(boolean fairness) {
|
||||||
return new ActiveLock();
|
return new ActiveLock(fairness);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,18 +37,31 @@ public class LockManager<R> {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(LockManager.class);
|
private static final Logger LOG = LoggerFactory.getLogger(LockManager.class);
|
||||||
|
|
||||||
private final Map<R, ActiveLock> activeLocks = new ConcurrentHashMap<>();
|
private final Map<R, ActiveLock> activeLocks = new ConcurrentHashMap<>();
|
||||||
private final GenericObjectPool<ActiveLock> lockPool =
|
private final GenericObjectPool<ActiveLock> lockPool;
|
||||||
new GenericObjectPool<>(new PooledLockFactory());
|
|
||||||
|
/**
|
||||||
|
* Creates new LockManager instance with the given Configuration.and uses
|
||||||
|
* non-fair mode for locks.
|
||||||
|
*
|
||||||
|
* @param conf Configuration object
|
||||||
|
*/
|
||||||
|
public LockManager(final Configuration conf) {
|
||||||
|
this(conf, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new LockManager instance with the given Configuration.
|
* Creates new LockManager instance with the given Configuration.
|
||||||
*
|
*
|
||||||
* @param conf Configuration object
|
* @param conf Configuration object
|
||||||
|
* @param fair - true to use fair lock ordering, else non-fair lock ordering.
|
||||||
*/
|
*/
|
||||||
public LockManager(final Configuration conf) {
|
public LockManager(final Configuration conf, boolean fair) {
|
||||||
final int maxPoolSize = conf.getInt(
|
final int maxPoolSize = conf.getInt(
|
||||||
HddsConfigKeys.HDDS_LOCK_MAX_CONCURRENCY,
|
HddsConfigKeys.HDDS_LOCK_MAX_CONCURRENCY,
|
||||||
HddsConfigKeys.HDDS_LOCK_MAX_CONCURRENCY_DEFAULT);
|
HddsConfigKeys.HDDS_LOCK_MAX_CONCURRENCY_DEFAULT);
|
||||||
|
lockPool =
|
||||||
|
new GenericObjectPool<>(new PooledLockFactory(fair));
|
||||||
lockPool.setMaxTotal(maxPoolSize);
|
lockPool.setMaxTotal(maxPoolSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,14 @@ import org.apache.commons.pool2.impl.DefaultPooledObject;
|
||||||
*/
|
*/
|
||||||
public class PooledLockFactory extends BasePooledObjectFactory<ActiveLock> {
|
public class PooledLockFactory extends BasePooledObjectFactory<ActiveLock> {
|
||||||
|
|
||||||
|
private boolean fairness;
|
||||||
|
|
||||||
|
PooledLockFactory(boolean fair) {
|
||||||
|
this.fairness = fair;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public ActiveLock create() throws Exception {
|
public ActiveLock create() throws Exception {
|
||||||
return ActiveLock.newInstance();
|
return ActiveLock.newInstance(fairness);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1529,6 +1529,17 @@
|
||||||
</description>
|
</description>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
|
<property>
|
||||||
|
<name>ozone.om.lock.fair</name>
|
||||||
|
<value>false</value>
|
||||||
|
<description>If this is true, the Ozone Manager lock will be used in Fair
|
||||||
|
mode, which will schedule threads in the order received/queued. If this is
|
||||||
|
false, uses non-fair ordering. See
|
||||||
|
java.util.concurrent.locks.ReentrantReadWriteLock
|
||||||
|
for more information on fair/non-fair locks.
|
||||||
|
</description>
|
||||||
|
</property>
|
||||||
|
|
||||||
<property>
|
<property>
|
||||||
<name>ozone.om.ratis.enable</name>
|
<name>ozone.om.ratis.enable</name>
|
||||||
<value>false</value>
|
<value>false</value>
|
||||||
|
|
|
@ -29,6 +29,9 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.ozone.lock.LockManager;
|
import org.apache.hadoop.ozone.lock.LockManager;
|
||||||
|
|
||||||
|
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_MANAGER_FAIR_LOCK_DEFAULT;
|
||||||
|
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_MANAGER_FAIR_LOCK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides different locks to handle concurrency in OzoneMaster.
|
* Provides different locks to handle concurrency in OzoneMaster.
|
||||||
* We also maintain lock hierarchy, based on the weight.
|
* We also maintain lock hierarchy, based on the weight.
|
||||||
|
@ -89,7 +92,9 @@ public class OzoneManagerLock {
|
||||||
* @param conf Configuration object
|
* @param conf Configuration object
|
||||||
*/
|
*/
|
||||||
public OzoneManagerLock(Configuration conf) {
|
public OzoneManagerLock(Configuration conf) {
|
||||||
manager = new LockManager<>(conf);
|
boolean fair = conf.getBoolean(OZONE_MANAGER_FAIR_LOCK,
|
||||||
|
OZONE_MANAGER_FAIR_LOCK_DEFAULT);
|
||||||
|
manager = new LockManager<>(conf, fair);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue