cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bened...@apache.org
Subject [4/6] cassandra git commit: Merge branch 'cassandra-2.2' into cassandra-3.0
Date Fri, 14 Aug 2015 19:29:39 GMT
Merge branch 'cassandra-2.2' into cassandra-3.0

Conflicts:
	test/unit/org/apache/cassandra/db/CommitLogTest.java


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/da8d48a7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/da8d48a7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/da8d48a7

Branch: refs/heads/trunk
Commit: da8d48a79abf031b6a4e7bfd381bd4689f2fc12c
Parents: b294058 c645b11
Author: Benedict Elliott Smith <benedict@apache.org>
Authored: Fri Aug 14 20:29:03 2015 +0100
Committer: Benedict Elliott Smith <benedict@apache.org>
Committed: Fri Aug 14 20:29:03 2015 +0100

----------------------------------------------------------------------
 .../db/CommitLogFailurePolicyTest.java          | 112 ++++++++++++++
 .../org/apache/cassandra/db/CommitLogTest.java  | 147 -------------------
 2 files changed, 112 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/da8d48a7/test/unit/org/apache/cassandra/db/CommitLogTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/db/CommitLogTest.java
index 0c5093a,2764da4..6db29a8
--- a/test/unit/org/apache/cassandra/db/CommitLogTest.java
+++ b/test/unit/org/apache/cassandra/db/CommitLogTest.java
@@@ -317,187 -319,32 +317,40 @@@ public class CommitLogTes
      }
  
      @Test
-     public void testCommitFailurePolicy_stop() throws ConfigurationException
-     {
-         CassandraDaemon daemon = new CassandraDaemon();
-         daemon.completeSetup(); //startup must be completed, otherwise commit log failure
must kill JVM regardless of failure policy
-         StorageService.instance.registerDaemon(daemon);
- 
-         // Need storage service active so stop policy can shutdown gossip
-         StorageService.instance.initServer();
-         Assert.assertTrue(Gossiper.instance.isEnabled());
- 
-         Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
-         try
-         {
-             DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.stop);
-             CommitLog.handleCommitError("Test stop error", new Throwable());
-             Assert.assertFalse(Gossiper.instance.isEnabled());
-         }
-         finally
-         {
-             DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
-         }
-     }
- 
-     @Test
-     public void testCommitFailurePolicy_die()
-     {
-         CassandraDaemon daemon = new CassandraDaemon();
-         daemon.completeSetup(); //startup must be completed, otherwise commit log failure
must kill JVM regardless of failure policy
-         StorageService.instance.registerDaemon(daemon);
- 
-         KillerForTests killerForTests = new KillerForTests();
-         JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
-         Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
-         try
-         {
-             DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.die);
-             CommitLog.handleCommitError("Testing die policy", new Throwable());
-             Assert.assertTrue(killerForTests.wasKilled());
-             Assert.assertFalse(killerForTests.wasKilledQuietly()); //only killed quietly
on startup failure
-         }
-         finally
-         {
-             DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
-             JVMStabilityInspector.replaceKiller(originalKiller);
-         }
-     }
- 
-     @Test
-     public void testCommitFailurePolicy_mustDieIfNotStartedUp()
-     {
-         //startup was not completed successfuly (since method completeSetup() was not called)
-         CassandraDaemon daemon = new CassandraDaemon();
-         StorageService.instance.registerDaemon(daemon);
- 
-         KillerForTests killerForTests = new KillerForTests();
-         JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
-         Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
-         try
-         {
-             //even though policy is ignore, JVM must die because Daemon has not finished
initializing
-             DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.ignore);
-             CommitLog.handleCommitError("Testing die policy", new Throwable());
-             Assert.assertTrue(killerForTests.wasKilled());
-             Assert.assertTrue(killerForTests.wasKilledQuietly()); //killed quietly due to
startup failure
-         }
-         finally
-         {
-             DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
-             JVMStabilityInspector.replaceKiller(originalKiller);
-         }
-     }
- 
-     @Test
-     public void testCommitLogFailureBeforeInitialization_mustKillJVM() throws Exception
-     {
-         //startup was not completed successfuly (since method completeSetup() was not called)
-         CassandraDaemon daemon = new CassandraDaemon();
-         StorageService.instance.registerDaemon(daemon);
- 
-         //let's make the commit log directory non-writable
-         File commitLogDir = new File(DatabaseDescriptor.getCommitLogLocation());
-         commitLogDir.setWritable(false);
- 
-         KillerForTests killerForTests = new KillerForTests();
-         JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
-         Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
-         try
-         {
-             DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.ignore);
- 
-             //now let's create a commit log segment manager and wait for it to fail
-             new CommitLogSegmentManager(CommitLog.instance).start();
- 
-             //busy wait since commitlogsegmentmanager spawns another thread
-             int retries = 0;
-             while (!killerForTests.wasKilled() && retries++ < 5)
-                 Thread.sleep(10);
- 
-             //since failure was before CassandraDaemon startup, the JVM must be killed
-             Assert.assertTrue(killerForTests.wasKilled());
-             Assert.assertTrue(killerForTests.wasKilledQuietly()); //killed quietly due to
startup failure
-         }
-         finally
-         {
-             DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
-             JVMStabilityInspector.replaceKiller(originalKiller);
-             commitLogDir.setWritable(true);
-         }
-     }
- 
-     @Test
-     public void testCommitLogFailureAfterInitialization_mustRespectFailurePolicy() throws
Exception
-     {
-         //startup was not completed successfuly (since method completeSetup() was not called)
-         CassandraDaemon daemon = new CassandraDaemon();
-         daemon.completeSetup(); //startup must be completed, otherwise commit log failure
must kill JVM regardless of failure policy
-         StorageService.instance.registerDaemon(daemon);
- 
-         //let's make the commit log directory non-writable
-         File commitLogDir = new File(DatabaseDescriptor.getCommitLogLocation());
-         commitLogDir.setWritable(false);
- 
-         KillerForTests killerForTests = new KillerForTests();
-         JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
-         Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
-         try
-         {
-             DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.ignore);
- 
-             //now let's create a commit log segment manager and wait for it to fail
-             new CommitLogSegmentManager(CommitLog.instance).start();
- 
-             //wait commit log segment manager thread to execute
-             Thread.sleep(50);
- 
-             //error policy is set to IGNORE, so JVM must not be killed if error ocurs after
startup
-             Assert.assertFalse(killerForTests.wasKilled());
-         }
-         finally
-         {
-             DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
-             JVMStabilityInspector.replaceKiller(originalKiller);
-             commitLogDir.setWritable(true);
-         }
-     }
- 
-     @Test
      public void testTruncateWithoutSnapshot() throws ExecutionException, InterruptedException,
IOException
      {
 -        CommitLog.instance.resetUnsafe(true);
 -        boolean prev = DatabaseDescriptor.isAutoSnapshot();
 -        DatabaseDescriptor.setAutoSnapshot(false);
 -        ColumnFamilyStore cfs1 = Keyspace.open(KEYSPACE1).getColumnFamilyStore("Standard1");
 -        ColumnFamilyStore cfs2 = Keyspace.open(KEYSPACE1).getColumnFamilyStore("Standard2");
 -
 -        final Mutation rm1 = new Mutation(KEYSPACE1, bytes("k"));
 -        rm1.add("Standard1", Util.cellname("c1"), ByteBuffer.allocate(100), 0);
 -        rm1.apply();
 -        cfs1.truncateBlocking();
 -        DatabaseDescriptor.setAutoSnapshot(prev);
 -        final Mutation rm2 = new Mutation(KEYSPACE1, bytes("k"));
 -        rm2.add("Standard2", Util.cellname("c1"), ByteBuffer.allocate(DatabaseDescriptor.getCommitLogSegmentSize()
/ 4), 0);
 -
 -        for (int i = 0 ; i < 5 ; i++)
 -            CommitLog.instance.add(rm2);
 -
 -        Assert.assertEquals(2, CommitLog.instance.activeSegments());
 -        ReplayPosition position = CommitLog.instance.getContext();
 -        for (Keyspace ks : Keyspace.system())
 -            for (ColumnFamilyStore syscfs : ks.getColumnFamilyStores())
 -                CommitLog.instance.discardCompletedSegments(syscfs.metadata.cfId, position);
 -        CommitLog.instance.discardCompletedSegments(cfs2.metadata.cfId, position);
 -        Assert.assertEquals(1, CommitLog.instance.activeSegments());
 +        boolean originalState = DatabaseDescriptor.isAutoSnapshot();
 +        try
 +        {
 +            CommitLog.instance.resetUnsafe(true);
 +            boolean prev = DatabaseDescriptor.isAutoSnapshot();
 +            DatabaseDescriptor.setAutoSnapshot(false);
 +            ColumnFamilyStore cfs1 = Keyspace.open(KEYSPACE1).getColumnFamilyStore(STANDARD1);
 +            ColumnFamilyStore cfs2 = Keyspace.open(KEYSPACE1).getColumnFamilyStore(STANDARD2);
 +
 +            new RowUpdateBuilder(cfs1.metadata, 0, "k").clustering("bytes").add("val", ByteBuffer.allocate(100)).build().applyUnsafe();
 +            cfs1.truncateBlocking();
 +            DatabaseDescriptor.setAutoSnapshot(prev);
 +            Mutation m2 = new RowUpdateBuilder(cfs2.metadata, 0, "k")
 +                          .clustering("bytes")
 +                          .add("val", ByteBuffer.allocate(DatabaseDescriptor.getCommitLogSegmentSize()
/ 4))
 +                          .build();
 +
 +            for (int i = 0 ; i < 5 ; i++)
 +                CommitLog.instance.add(m2);
 +
 +            assertEquals(2, CommitLog.instance.activeSegments());
 +            ReplayPosition position = CommitLog.instance.getContext();
 +            for (Keyspace ks : Keyspace.system())
 +                for (ColumnFamilyStore syscfs : ks.getColumnFamilyStores())
 +                    CommitLog.instance.discardCompletedSegments(syscfs.metadata.cfId, position);
 +            CommitLog.instance.discardCompletedSegments(cfs2.metadata.cfId, position);
 +            assertEquals(1, CommitLog.instance.activeSegments());
 +        }
 +        finally
 +        {
 +            DatabaseDescriptor.setAutoSnapshot(originalState);
 +        }
      }
  
      @Test


Mime
View raw message