Author: jbellis
Date: Wed Jun 24 19:25:12 2009
New Revision: 788144
URL: http://svn.apache.org/viewvc?rev=788144&view=rev
Log:
use normal Table for system metadata
patch by jbellis; reviewed by Jun Rao for CASSANDRA-235
Removed:
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/DBManagerTest.java
Modified:
incubator/cassandra/trunk/conf/storage-conf.xml
incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DBManager.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
incubator/cassandra/trunk/test/unit/org/apache/cassandra/CleanupHelper.java
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SystemTableTest.java
Modified: incubator/cassandra/trunk/conf/storage-conf.xml
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/conf/storage-conf.xml?rev=788144&r1=788143&r2=788144&view=diff
==============================================================================
--- incubator/cassandra/trunk/conf/storage-conf.xml (original)
+++ incubator/cassandra/trunk/conf/storage-conf.xml Wed Jun 24 19:25:12 2009
@@ -77,7 +77,6 @@
Keep the data disks and the CommitLog disks separate for best
performance
-->
<CommitLogDirectory>/var/cassandra/commitlog</CommitLogDirectory>
- <MetadataDirectory>/var/cassandra/system</MetadataDirectory>
<DataFileDirectories>
<DataFileDirectory>/var/cassandra/data</DataFileDirectory>
</DataFileDirectories>
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=788144&r1=788143&r2=788144&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
Wed Jun 24 19:25:12 2009
@@ -49,7 +49,6 @@
private static int replicationFactor_ = 3;
private static long rpcTimeoutInMillis_ = 2000;
private static Set<String> seeds_ = new HashSet<String>();
- private static String metadataDirectory_;
private static String snapshotDirectory_;
/* Keeps the list of Ganglia servers to contact */
private static String[] gangliaServers_ ;
@@ -242,22 +241,10 @@
columnIndexSizeInKB_ = Integer.parseInt(columnIndexSizeInKB);
}
- /* metadata directory */
- metadataDirectory_ =
xmlUtils.getNodeValue("/Storage/MetadataDirectory");
- if (metadataDirectory_ == null)
- {
- throw new ConfigurationException("MetadataDirectory must be
specified");
- }
- FileUtils.createDirectory(metadataDirectory_);
-
/* snapshot directory */
snapshotDirectory_ =
xmlUtils.getNodeValue("/Storage/SnapshotDirectory");
if ( snapshotDirectory_ != null )
FileUtils.createDirectory(snapshotDirectory_);
- else
- {
- snapshotDirectory_ = metadataDirectory_ +
System.getProperty("file.separator") + "snapshot";
- }
/* data file directory */
dataFileDirectories_ =
xmlUtils.getNodeValues("/Storage/DataFileDirectories/DataFileDirectory");
@@ -467,7 +454,7 @@
// Hardcoded system table
Table.TableMetadata tmetadata =
Table.TableMetadata.instance(Table.SYSTEM_TABLE);
- tmetadata.add(SystemTable.cfName_, cfId++);
+ tmetadata.add(SystemTable.LOCATION_CF, cfId++);
tmetadata.add(HintedHandOffManager.HINTS_CF, cfId++,
ColumnFamily.getColumnType("Super"));
}
@@ -683,16 +670,6 @@
return threadsPerPool_;
}
- public static String getMetadataDirectory()
- {
- return metadataDirectory_;
- }
-
- public static void setMetadataDirectory(String metadataDirectory)
- {
- metadataDirectory_ = metadataDirectory;
- }
-
public static String getSnapshotDirectory()
{
return snapshotDirectory_;
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DBManager.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DBManager.java?rev=788144&r1=788143&r2=788144&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DBManager.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DBManager.java
Wed Jun 24 19:25:12 2009
@@ -22,11 +22,7 @@
import java.util.Set;
import org.apache.cassandra.config.DatabaseDescriptor;
-import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.Token;
-import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.utils.BasicUtilities;
-import org.apache.cassandra.utils.FBUtilities;
/**
@@ -86,54 +82,4 @@
RecoveryManager recoveryMgr = RecoveryManager.instance();
recoveryMgr.doRecovery();
}
-
- /*
- * This method reads the system table and retrieves the metadata
- * associated with this storage instance. Currently we store the
- * metadata in a Column Family called LocatioInfo which has two
- * columns namely "Token" and "Generation". This is the token that
- * gets gossiped around and the generation info is used for FD.
- */
- public DBManager.StorageMetadata start() throws IOException
- {
- StorageMetadata storageMetadata = null;
- /* Read the system table to retrieve the storage ID and the generation
*/
- SystemTable sysTable = SystemTable.openSystemTable(SystemTable.name_);
- Row row = sysTable.get(FBUtilities.getHostAddress());
-
- IPartitioner p = StorageService.getPartitioner();
- if ( row == null )
- {
- Token token = p.getDefaultToken();
- int generation = 1;
-
- String key = FBUtilities.getHostAddress();
- row = new Row(SystemTable.name_, key);
- ColumnFamily cf = ColumnFamily.create("system",
SystemTable.cfName_); // TODO create system table
- cf.addColumn(new Column(SystemTable.token_,
p.getTokenFactory().toByteArray(token)));
- cf.addColumn(new Column(SystemTable.generation_,
BasicUtilities.intToByteArray(generation)) );
- row.addColumnFamily(cf);
- sysTable.apply(row);
- storageMetadata = new StorageMetadata( token, generation);
- }
- else
- {
- /* we crashed and came back up need to bump generation # */
- for (ColumnFamily columnFamily : row.getColumnFamilies())
- {
- IColumn tokenColumn =
columnFamily.getColumn(SystemTable.token_);
- Token token =
p.getTokenFactory().fromByteArray(tokenColumn.value());
-
- IColumn generation =
columnFamily.getColumn(SystemTable.generation_);
- int gen = BasicUtilities.byteArrayToInt(generation.value()) +
1;
-
- Column generation2 = new Column("Generation",
BasicUtilities.intToByteArray(gen), generation.timestamp() + 1);
- columnFamily.addColumn(generation2);
- storageMetadata = new StorageMetadata(token, gen);
- break; // TODO why break after one iteration?
- }
- sysTable.reset(row);
- }
- return storageMetadata;
- }
}
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java?rev=788144&r1=788143&r2=788144&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java
Wed Jun 24 19:25:12 2009
@@ -19,21 +19,13 @@
package org.apache.cassandra.db;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.log4j.Logger;
-import org.apache.cassandra.config.DatabaseDescriptor;
-import org.apache.cassandra.io.DataInputBuffer;
-import org.apache.cassandra.io.DataOutputBuffer;
-import org.apache.cassandra.io.IFileReader;
-import org.apache.cassandra.io.IFileWriter;
-import org.apache.cassandra.io.SequenceFile;
import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.utils.LogUtil;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.dht.IPartitioner;
+import org.apache.cassandra.utils.BasicUtilities;
/**
* Author : Avinash Lakshman ( [email protected]) & Prashant Malik (
[email protected] )
@@ -42,138 +34,72 @@
public class SystemTable
{
private static Logger logger_ = Logger.getLogger(SystemTable.class);
- private static Map<String, SystemTable> instances_ = new HashMap<String,
SystemTable>();
-
- /* Name of the SystemTable */
- public static final String name_ = "System";
- /* Name of the only column family in the Table */
- public static final String cfName_ = "LocationInfo";
- /* Name of columns in this table */
- static final String generation_ = "Generation";
- static final String token_ = "Token";
-
- /* The ID associated with this column family */
- static final int cfId_ = -1;
-
- /* Table name. */
- private String table_;
- /* after the header position */
- private long startPosition_ = 0L;
- /* Cache the SystemRow that we read. */
- private Row systemRow_;
-
- /* Use the following writer/reader to write/read to System table */
- private IFileWriter writer_;
- private IFileReader reader_;
-
- public static SystemTable openSystemTable(String tableName) throws
IOException
- {
- SystemTable table = instances_.get("System");
- if ( table == null )
- {
- table = new SystemTable(tableName);
- instances_.put(tableName, table);
- }
- return table;
- }
-
- SystemTable(String table) throws IOException
- {
- table_ = table;
- String systemTable = getFileName();
- writer_ = SequenceFile.writer(systemTable);
- reader_ = SequenceFile.reader(systemTable);
- }
-
- private String getFileName()
- {
- return DatabaseDescriptor.getMetadataDirectory() +
System.getProperty("file.separator") + table_ + ".db";
- }
+ public static final String LOCATION_CF = "LocationInfo";
+ private static final String LOCATION_KEY = "L"; // only one row in
Location CF
+ private static final String TOKEN = "Token";
+ private static final String GENERATION = "Generation";
/*
- * Selects the row associated with the given key.
+ * This method is used to update the SystemTable with the new token.
*/
- public Row get(String key) throws IOException
+ public static void updateToken(Token token) throws IOException
{
- DataOutputBuffer bufOut = new DataOutputBuffer();
- reader_.next(bufOut);
-
- if ( bufOut.getLength() > 0 )
- {
- DataInputBuffer bufIn = new DataInputBuffer();
- bufIn.reset(bufOut.getData(), bufOut.getLength());
- /*
- * This buffer contains key and value so we need to strip
- * certain parts
- */
- // read the key
- bufIn.readUTF();
- // read the data length and then deserialize
- bufIn.readInt();
- try
- {
- systemRow_ = Row.serializer().deserialize(bufIn);
- }
- catch ( IOException e )
- {
- logger_.debug( LogUtil.throwableToString(e) );
- }
- }
- return systemRow_;
+ IPartitioner p = StorageService.getPartitioner();
+ Table table = Table.open(Table.SYSTEM_TABLE);
+ /* Retrieve the "LocationInfo" column family */
+ ColumnFamily cf =
table.getColumnFamilyStore(LOCATION_CF).getColumnFamily(LOCATION_KEY,
LOCATION_KEY + ":" + TOKEN, new IdentityFilter());
+ long oldTokenColumnTimestamp =
cf.getColumn(SystemTable.TOKEN).timestamp();
+ /* create the "Token" whose value is the new token. */
+ IColumn tokenColumn = new Column(SystemTable.TOKEN,
p.getTokenFactory().toByteArray(token), oldTokenColumnTimestamp + 1);
+ /* replace the old "Token" column with this new one. */
+ logger_.debug("Replacing old token " +
p.getTokenFactory().fromByteArray(cf.getColumn(SystemTable.TOKEN).value()) + "
with " + token);
+ RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY);
+ cf.addColumn(tokenColumn);
+ rm.add(cf);
+ rm.apply();
}
/*
- * This is a one time thing and hence we do not need
- * any commit log related activity. Just write in an
- * atomic fashion to the underlying SequenceFile.
+ * This method reads the system table and retrieves the metadata
+ * associated with this storage instance. Currently we store the
+ * metadata in a Column Family called LocatioInfo which has two
+ * columns namely "Token" and "Generation". This is the token that
+ * gets gossiped around and the generation info is used for FD.
*/
- void apply(Row row) throws IOException
+ public static DBManager.StorageMetadata initMetadata() throws IOException
{
- systemRow_ = row;
- String file = getFileName();
- long currentPos = writer_.getCurrentPosition();
- DataOutputBuffer bufOut = new DataOutputBuffer();
- Row.serializer().serialize(row, bufOut);
- try
- {
- writer_.append(row.key(), bufOut);
- }
- catch ( IOException e )
- {
- writer_.seek(currentPos);
- throw e;
- }
- }
+ /* Read the system table to retrieve the storage ID and the generation
*/
+ Table table = Table.open(Table.SYSTEM_TABLE);
+ ColumnFamily cf =
table.getColumnFamilyStore(LOCATION_CF).getColumnFamily(LOCATION_KEY,
LOCATION_KEY + ":" + GENERATION, new IdentityFilter());
- /*
- * This method is used to update the SystemTable with the
- * new token.
- */
- public void updateToken(Token token) throws IOException
- {
IPartitioner p = StorageService.getPartitioner();
- if ( systemRow_ != null )
+ if (cf == null)
{
- /* Retrieve the "LocationInfo" column family */
- ColumnFamily columnFamily =
systemRow_.getColumnFamily(SystemTable.cfName_);
- long oldTokenColumnTimestamp =
columnFamily.getColumn(SystemTable.token_).timestamp();
- /* create the "Token" whose value is the new token. */
- IColumn tokenColumn = new Column(SystemTable.token_,
p.getTokenFactory().toByteArray(token), oldTokenColumnTimestamp + 1);
- /* replace the old "Token" column with this new one. */
- logger_.debug("Replacing old token " +
p.getTokenFactory().fromByteArray(columnFamily.getColumn(SystemTable.token_).value())
+ " with " + token);
- columnFamily.addColumn(tokenColumn);
- reset(systemRow_);
- }
- }
+ Token token = p.getDefaultToken();
+ int generation = 1;
- public void reset(Row row) throws IOException
- {
- writer_.seek(startPosition_);
- apply(row);
- }
+ RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY);
+ cf = ColumnFamily.create(Table.SYSTEM_TABLE,
SystemTable.LOCATION_CF);
+ cf.addColumn(new Column(TOKEN,
p.getTokenFactory().toByteArray(token)));
+ cf.addColumn(new Column(GENERATION,
BasicUtilities.intToByteArray(generation)) );
+ rm.add(cf);
+ rm.apply();
+ return new DBManager.StorageMetadata(token, generation);
+ }
- void delete(Row row) throws IOException
- {
- throw new UnsupportedOperationException("This operation is not
supported for System tables");
+ /* we crashed and came back up need to bump generation # */
+ IColumn tokenColumn = cf.getColumn(TOKEN);
+ Token token = p.getTokenFactory().fromByteArray(tokenColumn.value());
+
+ IColumn generation = cf.getColumn(GENERATION);
+ int gen = BasicUtilities.byteArrayToInt(generation.value()) + 1;
+
+ RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY);
+ cf = ColumnFamily.create(Table.SYSTEM_TABLE, SystemTable.LOCATION_CF);
+ Column generation2 = new Column(GENERATION,
BasicUtilities.intToByteArray(gen), generation.timestamp() + 1);
+ cf.addColumn(generation2);
+ rm.add(cf);
+ rm.apply();
+ return new DBManager.StorageMetadata(token, gen);
}
}
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=788144&r1=788143&r2=788144&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
Wed Jun 24 19:25:12 2009
@@ -25,7 +25,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.management.MBeanServer;
@@ -272,7 +271,7 @@
public void start() throws IOException
{
- storageMetadata_ = DBManager.instance().start();
+ storageMetadata_ = SystemTable.initMetadata();
tcpAddr_ = new EndPoint(DatabaseDescriptor.getStoragePort());
udpAddr_ = new EndPoint(DatabaseDescriptor.getControlPort());
/* Listen for application messages */
@@ -507,7 +506,7 @@
public void updateToken(Token token) throws IOException
{
/* update the token on disk */
- SystemTable.openSystemTable(SystemTable.name_).updateToken(token);
+ SystemTable.updateToken(token);
/* Update the storageMetadata cache */
storageMetadata_.setStorageId(token);
/* Update the token maps */
Modified:
incubator/cassandra/trunk/test/unit/org/apache/cassandra/CleanupHelper.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/CleanupHelper.java?rev=788144&r1=788143&r2=788144&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/CleanupHelper.java
(original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/CleanupHelper.java
Wed Jun 24 19:25:12 2009
@@ -38,7 +38,6 @@
DatabaseDescriptor.getBootstrapFileLocation(),
DatabaseDescriptor.getLogFileLocation(),
DatabaseDescriptor.getDataFileLocation(),
- DatabaseDescriptor.getMetadataDirectory(),
};
for (String dirName : directoryNames)
Modified:
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SystemTableTest.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SystemTableTest.java?rev=788144&r1=788143&r2=788144&view=diff
==============================================================================
---
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SystemTableTest.java
(original)
+++
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SystemTableTest.java
Wed Jun 24 19:25:12 2009
@@ -28,7 +28,9 @@
public class SystemTableTest extends CleanupHelper
{
@Test
- public void testMain() throws IOException {
-
SystemTable.openSystemTable(SystemTable.cfName_).updateToken(StorageService.getPartitioner().getInitialToken("503545744:0"));
+ public void testMain() throws IOException
+ {
+ SystemTable.initMetadata();
+
SystemTable.updateToken(StorageService.getPartitioner().getInitialToken("503545744:0"));
}
}