2015-05-18 14:27:39 +02:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you 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.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright 2015 Cloudius Systems
|
|
|
|
*
|
|
|
|
* Modified by Cloudius Systems
|
|
|
|
*/
|
|
|
|
package org.apache.cassandra.db.commitlog;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.lang.management.ManagementFactory;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import javax.management.MBeanServer;
|
|
|
|
import javax.management.ObjectName;
|
|
|
|
|
2015-07-06 13:24:59 +02:00
|
|
|
import org.apache.cassandra.metrics.CommitLogMetrics;
|
|
|
|
|
2015-12-17 08:26:19 +01:00
|
|
|
import com.scylladb.jmx.api.APIClient;
|
2015-05-18 14:27:39 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
public class CommitLog implements CommitLogMBean {
|
|
|
|
|
2015-07-06 13:24:59 +02:00
|
|
|
CommitLogMetrics metrics = new CommitLogMetrics();
|
2015-05-18 14:27:39 +02:00
|
|
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
|
|
|
.getLogger(CommitLog.class.getName());
|
|
|
|
|
|
|
|
private APIClient c = new APIClient();
|
|
|
|
|
|
|
|
public void log(String str) {
|
|
|
|
logger.info(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final CommitLog instance = new CommitLog();
|
|
|
|
|
|
|
|
public static CommitLog getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
2015-05-19 16:53:00 +02:00
|
|
|
|
2015-05-18 14:27:39 +02:00
|
|
|
private CommitLog() {
|
|
|
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
|
|
|
try {
|
2015-07-30 10:37:03 +02:00
|
|
|
mbs.registerMBean(this,
|
|
|
|
new ObjectName("org.apache.cassandra.db:type=Commitlog"));
|
2015-05-18 14:27:39 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of completed tasks
|
|
|
|
*
|
|
|
|
* @see org.apache.cassandra.metrics.CommitLogMetrics#completedTasks
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public long getCompletedTasks() {
|
|
|
|
log(" getCompletedTasks()");
|
|
|
|
return c.getLongValue("");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of tasks waiting to be executed
|
|
|
|
*
|
|
|
|
* @see org.apache.cassandra.metrics.CommitLogMetrics#pendingTasks
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public long getPendingTasks() {
|
|
|
|
log(" getPendingTasks()");
|
|
|
|
return c.getLongValue("");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current size used by all the commitlog segments.
|
|
|
|
*
|
|
|
|
* @see org.apache.cassandra.metrics.CommitLogMetrics#totalCommitLogSize
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public long getTotalCommitlogSize() {
|
|
|
|
log(" getTotalCommitlogSize()");
|
|
|
|
return c.getLongValue("");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recover a single file.
|
|
|
|
*/
|
|
|
|
public void recover(String path) throws IOException {
|
|
|
|
log(" recover(String path) throws IOException");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return file names (not full paths) of active commit log segments
|
|
|
|
* (segments containing unflushed data)
|
|
|
|
*/
|
|
|
|
public List<String> getActiveSegmentNames() {
|
|
|
|
log(" getActiveSegmentNames()");
|
2015-05-19 16:53:00 +02:00
|
|
|
List<String> lst = c.getListStrValue("/commitlog/segments/active");
|
|
|
|
Set<String> set = new HashSet<String>();
|
|
|
|
for (String l : lst) {
|
|
|
|
String name = l.substring(l.lastIndexOf("/") + 1, l.length());
|
|
|
|
set.add(name);
|
|
|
|
}
|
|
|
|
return new ArrayList<String>(set);
|
2015-05-18 14:27:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Files which are pending for archival attempt. Does NOT include
|
|
|
|
* failed archive attempts.
|
|
|
|
*/
|
|
|
|
public List<String> getArchivingSegmentNames() {
|
|
|
|
log(" getArchivingSegmentNames()");
|
2015-05-19 16:53:00 +02:00
|
|
|
List<String> lst = c.getListStrValue("/commitlog/segments/archiving");
|
|
|
|
Set<String> set = new HashSet<String>();
|
|
|
|
for (String l : lst) {
|
|
|
|
String name = l.substring(l.lastIndexOf("/") + 1, l.length());
|
|
|
|
set.add(name);
|
|
|
|
}
|
|
|
|
return new ArrayList<String>(set);
|
2015-05-18 14:27:39 +02:00
|
|
|
}
|
|
|
|
|
2015-07-30 11:01:05 +02:00
|
|
|
@Override
|
|
|
|
public String getArchiveCommand() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
log(" getArchiveCommand()");
|
|
|
|
return c.getStringValue("");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getRestoreCommand() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
log(" getRestoreCommand()");
|
|
|
|
return c.getStringValue("");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getRestoreDirectories() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
log(" getRestoreDirectories()");
|
|
|
|
return c.getStringValue("");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getRestorePointInTime() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
log(" getRestorePointInTime()");
|
|
|
|
return c.getLongValue("");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getRestorePrecision() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
log(" getRestorePrecision()");
|
|
|
|
return c.getStringValue("");
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:27:39 +02:00
|
|
|
}
|