Skip to content
Browse files

more javadoc

  • Loading branch information...
1 parent 9525768 commit 02fc07ec50ea67b6f36352afa5f05a4706ec5dc1 @jingwei jingwei committed Apr 24, 2012
Showing with 86 additions and 19 deletions.
  1. +85 −18 krati-main/src/main/java/krati/core/segment/SegmentManager.java
  2. +1 −1 pom.xml
View
103 krati-main/src/main/java/krati/core/segment/SegmentManager.java
@@ -123,36 +123,65 @@ private SegmentManager(String segmentHomePath, SegmentFactory segmentFactory, in
this._recycleLimit = computeRecycleLimit(segmentFileSizeMB);
this.open();
}
-
+
+ /**
+ * Computes the recycle limit based on the segment file size in MB.
+ *
+ * @param segmentFileSizeMB - the segment file size in MB
+ * @return the recycle limit
+ */
private int computeRecycleLimit(int segmentFileSizeMB) {
// Should always return an integer greater than zero.
return (segmentFileSizeMB <= 64) ? 5 : ((segmentFileSizeMB <= 256) ? 3 : 2);
}
-
+
+ /**
+ * Gets the segment file size in MB.
+ */
public int getSegmentFileSizeMB() {
return _segFileSizeMB;
}
-
+
+ /**
+ * Gets the file path to segment home.
+ */
public String getSegmentHomePath() {
return _segHomePath;
}
-
+
+ /**
+ * Gets the segment factory.
+ */
public SegmentFactory getSegmentFactory() {
return _segFactory;
}
-
+
+ /**
+ * Gets the current segment.
+ */
public Segment getCurrentSegment() {
return _segCurrent;
}
-
+
+ /**
+ * Gets the segment at the specified <code>index</code>.
+ *
+ * @param index - the segment index (i.e., segmentId)
+ */
public Segment getSegment(int index) {
return _segList.get(index);
}
-
+
+ /**
+ * Gets the count of segments managed by this SegmentManager.
+ */
public int getSegmentCount() {
return _segList.size();
}
-
+
+ /**
+ * Gets the count of live segments managed by this SegmentManager.
+ */
public int getLiveSegmentCount() {
int num = 0;
@@ -163,13 +192,16 @@ public int getLiveSegmentCount() {
return num;
}
-
+
+ /**
+ * Clears this SegmentManger.
+ */
public synchronized void clear() {
clearInternal(true /* CLEAR META */);
}
/**
- * Frees a segment.
+ * Frees the specified segment.
*/
public synchronized boolean freeSegment(Segment seg) throws IOException {
if (seg == null)
@@ -202,15 +234,15 @@ public synchronized boolean freeSegment(Segment seg) throws IOException {
return false;
}
-
+
/**
* Gets the next segment available for read and write.
*/
public synchronized Segment nextSegment() throws IOException {
_segCurrent = nextSegment(false);
return _segCurrent;
}
-
+
/**
* Gets the next segment available for read and write.
*
@@ -253,11 +285,21 @@ private synchronized Segment nextSegment(boolean newOnly) throws IOException {
return seg;
}
-
+
+ /**
+ * Initializes the segment meta file.
+ *
+ * @throws IOException
+ */
private void initMeta() throws IOException {
_segMeta = new SegmentMeta(new File(_segHomePath, ".meta"));
}
-
+
+ /**
+ * Initializes the segments managed by this SegmentManager
+ *
+ * @throws IOException
+ */
private void initSegs() throws IOException {
int loaded = 0;
File[] segFiles = listSegmentFiles();
@@ -293,7 +335,12 @@ private void initSegs() throws IOException {
_log.info("loaded: " + loaded + "/" + segFiles.length);
}
-
+
+ /**
+ * Clears this SegmentManager.
+ *
+ * @param clearMeta - whether to clear the segment meta file
+ */
private void clearInternal(boolean clearMeta) {
// Close all known segments
for(int segId = 0, cnt = _segList.size(); segId < cnt; segId++) {
@@ -336,6 +383,9 @@ private boolean recycle(Segment seg) {
return false;
}
+ /**
+ * Lists all the segment files managed by this SegmentManager.
+ */
protected File[] listSegmentFiles() {
File segDir = new File(_segHomePath);
File[] segFiles = segDir.listFiles(new FileFilter() {
@@ -364,15 +414,32 @@ public int compare(File f1, File f2) {
return segFiles;
}
-
+
+ /**
+ * Gets the meta data of all the segments managed by this SegmentManager.
+ */
public SegmentMeta getMeta() {
return _segMeta;
}
-
+
+ /**
+ * Updates the meta data of all the segments accordingly.
+ *
+ * @throws IOException
+ */
public synchronized void updateMeta() throws IOException {
_segMeta.wrap(this);
}
-
+
+ /**
+ * Gets the instance of SegmentManager for the specified <code>segmentHomePath</code>.
+ *
+ * @param segmentHomePath - the file path to segment home.
+ * @param segmentFactory - the segment factory
+ * @param segmentFileSizeMB - the segment file size in MB
+ * @return the instance of SegmentManager
+ * @throws IOException
+ */
public synchronized static SegmentManager getInstance(String segmentHomePath, SegmentFactory segmentFactory, int segmentFileSizeMB) throws IOException {
if (segmentFileSizeMB < Segment.minSegmentFileSizeMB) {
throw new IllegalArgumentException("Invalid argument segmentFileSizeMB " + segmentFileSizeMB + ", smaller than " + Segment.minSegmentFileSizeMB);
View
2 pom.xml
@@ -6,7 +6,7 @@
<artifactId>project</artifactId>
<packaging>pom</packaging>
<version>0.4.5-SNAPSHOT</version>
- <name>projects</name>
+ <name>project</name>
<description>A hash-based high-performance data store</description>
<url>http://sna-projects.com/krati</url>

0 comments on commit 02fc07e

Please sign in to comment.
Something went wrong with that request. Please try again.