snapshot must be performed before flushlock must be acquired, or we deadlock. See #2381

patch by jbellis

git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1087402 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2011-03-31 18:34:56 +00:00
parent acde48fb3d
commit 95809de586
3 changed files with 26 additions and 4 deletions

View File

@ -80,11 +80,12 @@ public class DropColumnFamily extends Migration
if (!clientMode) if (!clientMode)
{ {
cfs.snapshot(Table.getTimestampedSnapshotName(null));
CompactionManager.instance.getCompactionLock().lock(); CompactionManager.instance.getCompactionLock().lock();
cfs.flushLock.lock(); cfs.flushLock.lock();
try try
{ {
cfs.snapshot(Table.getTimestampedSnapshotName(null));
Table.open(ksm.name).dropCf(cfm.cfId); Table.open(ksm.name).dropCf(cfm.cfId);
} }
finally finally

View File

@ -63,10 +63,10 @@ public class DropKeyspace extends Migration
CFMetaData.purge(cfm); CFMetaData.purge(cfm);
if (!clientMode) if (!clientMode)
{ {
cfs.snapshot(snapshotName);
cfs.flushLock.lock(); cfs.flushLock.lock();
try try
{ {
cfs.snapshot(snapshotName);
Table.open(ksm.name).dropCf(cfm.cfId); Table.open(ksm.name).dropCf(cfm.cfId);
} }
finally finally

View File

@ -411,7 +411,7 @@ public class DefsTest extends CleanupHelper
assert ks != null; assert ks != null;
final CFMetaData cfm = ks.cfMetaData().get("Standard2"); final CFMetaData cfm = ks.cfMetaData().get("Standard2");
assert cfm != null; assert cfm != null;
// write some data, force a flush, then verify that files exist on disk. // write some data, force a flush, then verify that files exist on disk.
RowMutation rm = new RowMutation(ks.name, dk.key); RowMutation rm = new RowMutation(ks.name, dk.key);
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
@ -451,7 +451,28 @@ public class DefsTest extends CleanupHelper
assert th instanceof NullPointerException; assert th instanceof NullPointerException;
} }
} }
@Test
public void dropKSUnflushed() throws ConfigurationException, IOException, ExecutionException, InterruptedException
{
DecoratedKey dk = Util.dk("dropKs");
// sanity
final KSMetaData ks = DatabaseDescriptor.getTableDefinition("Keyspace3");
assert ks != null;
final CFMetaData cfm = ks.cfMetaData().get("Standard1");
assert cfm != null;
// write some data
RowMutation rm = new RowMutation(ks.name, dk.key);
for (int i = 0; i < 100; i++)
rm.add(new QueryPath(cfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L);
rm.apply();
new DropKeyspace(ks.name).apply();
assert DatabaseDescriptor.getTableDefinition(ks.name) == null;
}
@Test @Test
public void renameKs() throws ConfigurationException, IOException, ExecutionException, InterruptedException public void renameKs() throws ConfigurationException, IOException, ExecutionException, InterruptedException
{ {