Skip to content

Commit

Permalink
OAK-6227: There should be a way to retrieve oldest timestamp to keep …
Browse files Browse the repository at this point in the history
…from nodestores

Simplify checkpoint mbean method - expose 2 methods now: one for timestamp and another for human redable date

OAK-2808: Active deletion of 'deleted' Lucene index files from DataStore without relying on full scale Blob GC

Refactor wrt change in checkpoint mbean method simplification. Also minor change to not flush files if there were no blobs that were deleted.

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1797778 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
catholicon committed Jun 6, 2017
1 parent a4cb5ea commit 6680856
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

package org.apache.jackrabbit.oak.api.jmx;

import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;

import aQute.bnd.annotation.ProviderType;

import java.util.Date;

/**
* MBean for managing {@code org.apache.jackrabbit.oak.spi.state.NodeStore#checkpoint checkpoints}.
*/
Expand All @@ -39,9 +40,14 @@ public interface CheckpointMBean {
TabularData listCheckpoints();

/**
* @return creation information about oldest checkpoint.
* @return creation timestamp of oldest checkpoint.
*/
long getOldestCheckpointCreationTimestamp();

/**
* @return creation date of oldest checkpoint.
*/
CompositeData getOldestCheckpointCreationTime();
Date getOldestCheckpointCreationDate();

/**
* Create a new checkpoint with the given {@code lifetime}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
import java.util.Map.Entry;

import javax.management.openmbean.ArrayType;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;

import com.google.common.collect.Maps;
import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;

/**
Expand Down Expand Up @@ -94,24 +91,12 @@ public TabularData listCheckpoints() {
}
}

protected abstract long getOldestCheckpointCreationTimestamp();
@Override
public abstract long getOldestCheckpointCreationTimestamp();

@Override
public CompositeData getOldestCheckpointCreationTime() {
try {
Map<String, Object> values = Maps.newHashMap();
long timestamp = getOldestCheckpointCreationTimestamp();
values.put("timestamp", timestamp);
values.put("time", new Date(timestamp));
CompositeDataSupport csd = new CompositeDataSupport(
new CompositeType("OldestCheckpointTime", "Creation time of oldest checkpoint",
new String[]{"timestamp", "time"}, new String[]{"epoch timestamp", "human readable date"},
new OpenType[]{SimpleType.LONG, SimpleType.DATE}), values);

return csd;
} catch (OpenDataException e) {
throw new IllegalStateException(e);
}
public Date getOldestCheckpointCreationDate() {
return new Date(getOldestCheckpointCreationTimestamp());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void collectCheckpoints(TabularDataSupport tab) throws OpenDataExcepti
}

@Override
protected long getOldestCheckpointCreationTimestamp() {
public long getOldestCheckpointCreationTimestamp() {
Map<Revision, Info> checkpoints = store.getCheckpoints().getCheckpoints();

long minTimestamp = Long.MAX_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import javax.annotation.Nonnull;
import javax.management.NotCompliantMBeanException;
import javax.management.openmbean.CompositeData;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -736,21 +735,11 @@ private void initializeActiveBlobCollector(Whiteboard whiteboard, Map<String, ?>
private long getSafeTimestampForDeletedBlobs(CheckpointMBean checkpointMBean) {
long timestamp = clock.getTime() - TimeUnit.SECONDS.toMillis(MIN_BLOB_AGE_TO_ACTIVELY_DELETE);

CompositeData data = checkpointMBean.getOldestCheckpointCreationTime();
Object timestampObj = data.get("timestamp");
String timestampStr = null;
if (timestampObj != null) {
timestampStr = timestampObj.toString();
}
try {
long minCheckpointTimestamp = Long.parseLong(timestampStr);
if (minCheckpointTimestamp < timestamp) {
log.info("Oldest checkpoint time data ({}) is older than buffer period for deleted blobs." +
" Using that instead", data);
timestamp = minCheckpointTimestamp;
}
} catch (NumberFormatException nfe) {
log.warn("Couldn't find timestamp in checkpoint mbean output: {}", data);
long minCheckpointTimestamp = checkpointMBean.getOldestCheckpointCreationTimestamp();
if (minCheckpointTimestamp < timestamp) {
log.info("Oldest checkpoint timestamp ({}) is older than buffer period ({}) for deleted blobs." +
" Using that instead", minCheckpointTimestamp, timestamp);
timestamp = minCheckpointTimestamp;
}

return timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,15 @@ private synchronized void flushDeletedBlobs() {
while (deletedBlobs.peek() != null) {
localDeletedBlobs.add(deletedBlobs.poll());
}
File outFile = new File(rootDirectory, getBlobFileName());
try {
long start = PERF_LOG.start();
FileUtils.writeLines(outFile, localDeletedBlobs, true);
PERF_LOG.end(start, 1, "Flushing deleted blobs");
} catch (IOException e) {
LOG.error("Couldn't write out to " + outFile, e);
if (localDeletedBlobs.size() > 0) {
File outFile = new File(rootDirectory, getBlobFileName());
try {
long start = PERF_LOG.start();
FileUtils.writeLines(outFile, localDeletedBlobs, true);
PERF_LOG.end(start, 1, "Flushing deleted blobs");
} catch (IOException e) {
LOG.error("Couldn't write out to " + outFile, e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void collectCheckpoints(TabularDataSupport tab) throws OpenDataExcepti
}

@Override
protected long getOldestCheckpointCreationTimestamp() {
public long getOldestCheckpointCreationTimestamp() {
long minTimestamp = Long.MAX_VALUE;
for (ChildNodeEntry cne : store.getCheckpoints().getChildNodeEntries()) {
NodeState checkpoint = cne.getNodeState();
Expand Down

0 comments on commit 6680856

Please sign in to comment.