Rework CommitLog

This commit is contained in:
elcallio 2016-10-11 14:05:15 +02:00 committed by Calle Wilund
parent e55863e375
commit 1470b37193

View File

@ -23,7 +23,6 @@
package org.apache.cassandra.db.commitlog; package org.apache.cassandra.db.commitlog;
import java.io.IOException; import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -31,48 +30,31 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.cassandra.metrics.CommitLogMetrics; import org.apache.cassandra.metrics.CommitLogMetrics;
import com.scylladb.jmx.api.APIClient; import com.scylladb.jmx.api.APIClient;
import com.scylladb.jmx.metrics.MetricsMBean;
/* /*
* Commit Log tracks every write operation into the system. The aim of the commit log is to be able to * Commit Log tracks every write operation into the system. The aim of the commit log is to be able to
* successfully recover data that was not stored to disk via the Memtable. * successfully recover data that was not stored to disk via the Memtable.
*/ */
public class CommitLog implements CommitLogMBean { public class CommitLog extends MetricsMBean implements CommitLogMBean {
CommitLogMetrics metrics = new CommitLogMetrics();
private static final java.util.logging.Logger logger = java.util.logging.Logger private static final java.util.logging.Logger logger = java.util.logging.Logger
.getLogger(CommitLog.class.getName()); .getLogger(CommitLog.class.getName());
private APIClient c = new APIClient();
public void log(String str) { public void log(String str) {
logger.finest(str); logger.finest(str);
} }
private static final CommitLog instance = new CommitLog(); public CommitLog(APIClient client) {
super("org.apache.cassandra.db:type=Commitlog", client, new CommitLogMetrics());
public static CommitLog getInstance() {
return instance;
}
private CommitLog() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
mbs.registerMBean(this,
new ObjectName("org.apache.cassandra.db:type=Commitlog"));
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
/** /**
* Recover a single file. * Recover a single file.
*/ */
@Override
public void recover(String path) throws IOException { public void recover(String path) throws IOException {
log(" recover(String path) throws IOException"); log(" recover(String path) throws IOException");
} }
@ -81,9 +63,10 @@ public class CommitLog implements CommitLogMBean {
* @return file names (not full paths) of active commit log segments * @return file names (not full paths) of active commit log segments
* (segments containing unflushed data) * (segments containing unflushed data)
*/ */
@Override
public List<String> getActiveSegmentNames() { public List<String> getActiveSegmentNames() {
log(" getActiveSegmentNames()"); log(" getActiveSegmentNames()");
List<String> lst = c.getListStrValue("/commitlog/segments/active"); List<String> lst = client.getListStrValue("/commitlog/segments/active");
Set<String> set = new HashSet<String>(); Set<String> set = new HashSet<String>();
for (String l : lst) { for (String l : lst) {
String name = l.substring(l.lastIndexOf("/") + 1, l.length()); String name = l.substring(l.lastIndexOf("/") + 1, l.length());
@ -96,9 +79,10 @@ public class CommitLog implements CommitLogMBean {
* @return Files which are pending for archival attempt. Does NOT include * @return Files which are pending for archival attempt. Does NOT include
* failed archive attempts. * failed archive attempts.
*/ */
@Override
public List<String> getArchivingSegmentNames() { public List<String> getArchivingSegmentNames() {
log(" getArchivingSegmentNames()"); log(" getArchivingSegmentNames()");
List<String> lst = c.getListStrValue("/commitlog/segments/archiving"); List<String> lst = client.getListStrValue("/commitlog/segments/archiving");
Set<String> set = new HashSet<String>(); Set<String> set = new HashSet<String>();
for (String l : lst) { for (String l : lst) {
String name = l.substring(l.lastIndexOf("/") + 1, l.length()); String name = l.substring(l.lastIndexOf("/") + 1, l.length());
@ -111,35 +95,35 @@ public class CommitLog implements CommitLogMBean {
public String getArchiveCommand() { public String getArchiveCommand() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
log(" getArchiveCommand()"); log(" getArchiveCommand()");
return c.getStringValue(""); return client.getStringValue("");
} }
@Override @Override
public String getRestoreCommand() { public String getRestoreCommand() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
log(" getRestoreCommand()"); log(" getRestoreCommand()");
return c.getStringValue(""); return client.getStringValue("");
} }
@Override @Override
public String getRestoreDirectories() { public String getRestoreDirectories() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
log(" getRestoreDirectories()"); log(" getRestoreDirectories()");
return c.getStringValue(""); return client.getStringValue("");
} }
@Override @Override
public long getRestorePointInTime() { public long getRestorePointInTime() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
log(" getRestorePointInTime()"); log(" getRestorePointInTime()");
return c.getLongValue(""); return client.getLongValue("");
} }
@Override @Override
public String getRestorePrecision() { public String getRestorePrecision() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
log(" getRestorePrecision()"); log(" getRestorePrecision()");
return c.getStringValue(""); return client.getStringValue("");
} }
@Override @Override
@ -150,7 +134,7 @@ public class CommitLog implements CommitLogMBean {
@Override @Override
public long getActiveOnDiskSize() { public long getActiveOnDiskSize() {
return c.getLongValue("/commitlog/metrics/total_commit_log_size"); return client.getLongValue("/commitlog/metrics/total_commit_log_size");
} }
@Override @Override