Permalink
Browse files

Code cleanup

  • Loading branch information...
1 parent 4db8cc3 commit 32fb76a370e1bc063e0207ec0ca9b9906e17a633 @abh1nay abh1nay committed Nov 20, 2012
@@ -203,6 +203,9 @@
private boolean rebalancingOptimization;
private boolean usePartitionScanForRebalance;
+ // flag to indicate if we will mlock and pin index pages in memory
+ private boolean useMlock;
+
public VoldemortConfig(Properties props) {
this(new Props(props));
}
@@ -267,6 +270,8 @@ public VoldemortConfig(Props props) {
this.fetcherBufferSize = (int) props.getBytes("hdfs.fetcher.buffer.size",
DEFAULT_BUFFER_SIZE);
+ this.setUseMlock(props.getBoolean("readonly.mlock.index", false));
+
this.mysqlUsername = props.getString("mysql.user", "root");
this.mysqlPassword = props.getString("mysql.password", "");
this.mysqlHost = props.getString("mysql.host", "localhost");
@@ -1919,4 +1924,12 @@ public OpTimeMap testingGetSlowQueueingDelays() {
public OpTimeMap testingGetSlowConcurrentDelays() {
return this.testingSlowConcurrentDelays;
}
+
+ public boolean isUseMlock() {
+ return useMlock;
+ }
+
+ public void setUseMlock(boolean useMlock) {
+ this.useMlock = useMlock;
+ }
}
@@ -46,6 +46,7 @@
private final int nodeId;
private RoutingStrategy routingStrategy = null;
private final int deleteBackupMs;
+ private boolean enforceMlock = false;
public ReadOnlyStorageConfiguration(VoldemortConfig config) {
this.storageDir = new File(config.getReadOnlyDataStorageDirectory());
@@ -55,6 +56,7 @@ public ReadOnlyStorageConfiguration(VoldemortConfig config) {
.trim()));
this.nodeId = config.getNodeId();
this.deleteBackupMs = config.getReadOnlyDeleteBackupMs();
+ this.enforceMlock = config.isUseMlock();
}
public void close() {
@@ -77,7 +79,8 @@ public void setRoutingStrategy(RoutingStrategy routingStrategy) {
new File(storageDir,
storeDef.getName()),
numBackups,
- deleteBackupMs);
+ deleteBackupMs,
+ enforceMlock);
ObjectName objName = JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()),
storeDef.getName() + nodeId);
JmxUtils.registerMbean(ManagementFactory.getPlatformMBeanServer(),
@@ -69,6 +69,7 @@
private volatile boolean isOpen;
private int deleteBackupMs = 0;
private long lastSwapped;
+ private boolean enforceMlock = false;
/**
* Create an instance of the store
@@ -126,6 +127,22 @@ public ReadOnlyStorageEngine(String name,
open(null);
}
+ /*
+ * Overload constructor to accept the mlock config
+ */
+ public ReadOnlyStorageEngine(String name,
+ SearchStrategy searchStrategy,
+ RoutingStrategy routingStrategy,
+ int nodeId,
+ File storeDir,
+ int numBackups,
+ int deleteBackupMs,
+ boolean enforceMlock) {
+
+ this(name, searchStrategy, routingStrategy, nodeId, storeDir, numBackups, deleteBackupMs);
+ this.enforceMlock = enforceMlock;
+ }
+
/**
* Returns the internal chunked file set
*
@@ -186,7 +203,7 @@ public void open(File versionDir) {
+ versionDir.getAbsolutePath());
Utils.symlink(versionDir.getAbsolutePath(), storeDir.getAbsolutePath() + File.separator
+ "latest");
- this.fileSet = new ChunkedFileSet(versionDir, routingStrategy, nodeId);
+ this.fileSet = new ChunkedFileSet(versionDir, routingStrategy, nodeId, enforceMlock);
this.lastSwapped = System.currentTimeMillis();
this.isOpen = true;
} finally {
@@ -55,6 +55,16 @@
private RoutingStrategy routingStrategy;
private ReadOnlyStorageFormat storageFormat;
+ private boolean enforceMlock = false;
+
+ public ChunkedFileSet(File directory,
+ RoutingStrategy routingStrategy,
+ int nodeId,
+ boolean enforceMlock) {
+ this(directory, routingStrategy, nodeId);
+ this.enforceMlock = enforceMlock;
+ }
+
public ChunkedFileSet(File directory, RoutingStrategy routingStrategy, int nodeId) {
this.baseDir = directory;
if(!Utils.isReadableDir(directory))
@@ -158,10 +168,10 @@ else if(index.exists() ^ data.exists())
try {
idxFileReader = new MappedFileReader(index);
mappedIndexFileReader.add(idxFileReader);
- indexFiles.add(idxFileReader.map());
+ indexFiles.add(idxFileReader.map(enforceMlock));
} catch(IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+
+ logger.error("Error in mlock", e);
}
// indexFiles.add(mapFile(index));
@@ -221,10 +231,9 @@ public void initVersion1() {
try {
idxFileReader = new MappedFileReader(index);
mappedIndexFileReader.add(idxFileReader);
- indexFiles.add(idxFileReader.map());
+ indexFiles.add(idxFileReader.map(enforceMlock));
} catch(IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error("Error in mlock", e);
}
// indexFiles.add(mapFile(index));
@@ -314,10 +323,9 @@ public void initVersion2() {
try {
idxFileReader = new MappedFileReader(index);
mappedIndexFileReader.add(idxFileReader);
- indexFiles.add(idxFileReader.map());
+ indexFiles.add(idxFileReader.map(enforceMlock));
} catch(IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error("Error in mlock", e);
}
// indexFiles.add(mapFile(index));
@@ -10,8 +10,6 @@
import org.apache.log4j.Logger;
-import voldemort.store.readonly.io.jna.fcntl;
-
/**
* Facade around a MappedByteBuffer but we also support mlock on the mapped
* pages, and closing all dependent resources.
@@ -21,13 +19,8 @@
private static final Logger log = Logger.getLogger(MappedFileReader.class);
- public static boolean DEFAULT_AUTO_LOCK = true;
-
protected FileInputStream in;
- // TODO expose this as a server side config
- protected boolean autoLock = DEFAULT_AUTO_LOCK;
-
protected MappedByteBuffer mappedByteBuffer = null;
public MappedFileReader(String path) throws IOException {
@@ -55,18 +48,13 @@ private void init(File file) throws IOException {
/**
* Read from this mapped file.
*/
- public MappedByteBuffer map() throws IOException {
+ public MappedByteBuffer map(boolean setAutoLock) throws IOException {
try {
- // in JDK 1.6 and earlier the max mmap we could have was 2GB so to
- // route around this problem we create a number of smaller mmap
- // files , one per 2GB region and then use a composite channel
- // buffer
-
if(mappedByteBuffer == null) {
- if(autoLock) {
+ if(setAutoLock) {
closer.add(new MemLock(file, in.getFD(), offset, length));
}
@@ -80,6 +68,11 @@ public MappedByteBuffer map() throws IOException {
} catch(IOException e) {
+ log.error(String.format("Failed to map %s of length %,d at %,d",
+ file.getPath(),
+ length,
+ offset), e);
+
throw new IOException(String.format("Failed to map %s of length %,d at %,d",
file.getPath(),
length,
@@ -89,14 +82,6 @@ public MappedByteBuffer map() throws IOException {
}
- public boolean getAutoLock() {
- return this.autoLock;
- }
-
- public void setAutoLock(boolean autoLock) {
- this.autoLock = autoLock;
- }
-
@Override
public void close() throws IOException {
@@ -124,10 +109,6 @@ public void close() throws IOException {
super.close();
- if(fadvise) {
- fcntl.posix_fadvise(fd, offset, length, fcntl.POSIX_FADV_RANDOM);
- }
-
}
}
@@ -42,7 +42,7 @@ public MemLock(File file, FileDescriptor descriptor, long offset, long length)
int fd = voldemort.store.readonly.io.Native.getFd(descriptor);
- pa = mman.mmap(length, mman.PROT_READ, mman.MAP_SHARED | mman.MAP_LOCKED, fd, offset);
+ pa = mman.mmap(length, mman.PROT_READ, mman.MAP_SHARED, fd, offset);
// even though technically we have specified MAP_LOCKED this isn't
// supported on OpenSolaris or older Linux kernels (or OS X).
@@ -1,18 +1,3 @@
-/*
- * Copyright 2011 Kevin A. Burton
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
package voldemort.store.readonly.io.jna;
import com.sun.jna.Library;
@@ -2,6 +2,7 @@
import java.io.IOException;
+import org.apache.log4j.Logger;
import com.sun.jna.Native;
@@ -14,6 +15,8 @@
public static final int POSIX_FADV_DONTNEED = 4; /* fadvise.h */
public static final int POSIX_FADV_NOREUSE = 5; /* fadvise.h */
+ private static final Logger logger = Logger.getLogger(fcntl.class);
+
/**
* <b>posix documentation</b>
*
@@ -145,8 +148,9 @@ public static int posix_fallocate(int fd, long offset, long len) throws IOExcept
int result = Delegate.posix_fallocate(fd, offset, len);
- if(result != 0)
- throw new IOException(errno.strerror(result));
+ if(result != 0) {
+ logger.warn(errno.strerror(result));
+ }
return result;
@@ -77,6 +77,8 @@ public static void munlock(Pointer addr, long len) throws IOException {
if(Delegate.munlock(addr, len) != 0) {
logger.warn(errno.strerror());
+ } else {
+ logger.info("munlocking region");
}
}

0 comments on commit 32fb76a

Please sign in to comment.