aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject git commit: Now treating empty log file as new log file in test.
Date Mon, 16 Dec 2013 18:19:54 GMT
Updated Branches:
  refs/heads/master 39a94c1a9 -> 8bb538f13


Now treating empty log file as new log file in test.

Testing Done:
Gradle clean build.

Tested with the isolated scheduler and an empty log file.
?  git:(master) ? ls -lh /tmp/testing_log_file                                           
                                                              ~/workspace/incubator-aurora
-rw-r--r--  1 skarumuri  wheel     0B Dec 13 14:56 /tmp/testing_log_file

Ran it on master:

Running on an empty file would result in an exception as follows:

E1213 22:58:26.660 THREAD1 org.apache.zookeeper.server.NIOServerCnxn$Factory$1.uncaughtException:
Thread Thread[main,5,main] died
java.lang.IllegalStateException: Failed to open the log, cannot continue
	at com.twitter.aurora.scheduler.storage.log.LogStorage.prepare(LogStorage.java:289)
	at com.twitter.aurora.scheduler.storage.CallOrderEnforcingStorage.prepare(CallOrderEnforcingStorage.java:80)
	at com.twitter.aurora.scheduler.SchedulerLifecycle.prepare(SchedulerLifecycle.java:144)
	at com.twitter.aurora.scheduler.app.SchedulerMain.run(SchedulerMain.java:255)
	at com.twitter.common.application.AppLauncher.run(AppLauncher.java:102)
	at com.twitter.common.application.AppLauncher.launch(AppLauncher.java:181)
	at com.twitter.common.application.AppLauncher.launch(AppLauncher.java:142)
	at com.twitter.aurora.scheduler.app.SchedulerMain.main(SchedulerMain.java:276)
Caused by: java.io.IOException: Failed to interpret log contents: com.twitter.aurora.codec.ThriftBinaryCodec$CodingException:
Failed to deserialize thrift object.
	at com.twitter.aurora.scheduler.log.testing.FileLog.open(FileLog.java:80)
	at com.twitter.aurora.scheduler.storage.log.LogManager.open(LogManager.java:123)
	at com.twitter.aurora.scheduler.storage.log.LogStorage.prepare(LogStorage.java:287)
	... 7 more
Caused by: com.twitter.aurora.codec.ThriftBinaryCodec$CodingException: Failed to deserialize
thrift object.
	at com.twitter.aurora.codec.ThriftBinaryCodec.decodeNonNull(ThriftBinaryCodec.java:86)
	at com.twitter.aurora.codec.ThriftBinaryCodec.decode(ThriftBinaryCodec.java:59)
	at com.twitter.aurora.scheduler.log.testing.FileLog.open(FileLog.java:67)
	... 9 more
Caused by: org.apache.thrift.transport.TTransportException: Cannot read. Remote side has closed.
Tried to read 1 bytes, but only got 0 bytes. (This is often indicative of an internal error
on the server side. Please check your server logs.)
	at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
	at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:362)
	at org.apache.thrift.protocol.TBinaryProtocol.readByte(TBinaryProtocol.java:251)
	at org.apache.thrift.protocol.TBinaryProtocol.readFieldBegin(TBinaryProtocol.java:215)
	at com.twitter.aurora.gen.test.FileLogContents$FileLogContentsStandardScheme.read(FileLogContents.java:349)
	at com.twitter.aurora.gen.test.FileLogContents$FileLogContentsStandardScheme.read(FileLogContents.java:342)
	at com.twitter.aurora.gen.test.FileLogContents.read(FileLogContents.java:292)
	at org.apache.thrift.TDeserializer.deserialize(TDeserializer.java:69)
	at com.twitter.aurora.codec.ThriftBinaryCodec.decodeNonNull(ThriftBinaryCodec.java:79)
	... 11 more

I1213 22:58:27.001 THREAD11 org.apache.zookeeper.server.SessionTrackerImpl.run: SessionTrackerImpl
exited loop!
UnresettableLogManager is ignoring a reset() request.
I1213 22:58:27.002 THREAD14 com.twitter.common.application.ShutdownRegistry$ShutdownRegistryImpl.execute:
Action controller has already completed, subsequent calls ignored.

After the fix: No exception.

Reviewed at https://reviews.apache.org/r/16261/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/8bb538f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/8bb538f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/8bb538f1

Branch: refs/heads/master
Commit: 8bb538f1385447d974b58d21d7f39b1534283a32
Parents: 39a94c1
Author: Suman Karumuri <suman.karumuri+rb@gmail.com>
Authored: Mon Dec 16 10:18:20 2013 -0800
Committer: Suman Karumuri <skarumuri@twitter.com>
Committed: Mon Dec 16 10:18:20 2013 -0800

----------------------------------------------------------------------
 .../aurora/scheduler/log/testing/FileLog.java   |  7 ++-
 .../scheduler/log/testing/FileLogTest.java      | 58 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8bb538f1/src/main/java/com/twitter/aurora/scheduler/log/testing/FileLog.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/twitter/aurora/scheduler/log/testing/FileLog.java b/src/main/java/com/twitter/aurora/scheduler/log/testing/FileLog.java
index cb5cc87..3dff4cf 100644
--- a/src/main/java/com/twitter/aurora/scheduler/log/testing/FileLog.java
+++ b/src/main/java/com/twitter/aurora/scheduler/log/testing/FileLog.java
@@ -18,6 +18,7 @@ package com.twitter.aurora.scheduler.log.testing;
 import java.io.File;
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
 import java.util.Iterator;
 
 import javax.inject.Inject;
@@ -61,7 +62,11 @@ class FileLog implements Log {
   public Stream open() throws IOException {
     try {
       FileLogContents logContents;
-      if (logFile.createNewFile()) {
+      // Treat an empty file as a new file.
+      // NOTE: we can't use logFile.length == 0 to test for an empty file, since empty unicode
files
+      // contain a byte order mark (BOM) header that is 255 bytes in length.
+      if (logFile.createNewFile()
+          || Files.readFirstLine(logFile, Charset.defaultCharset()) == null) {
         logContents = new FileLogContents(Maps.<Long, LogRecord>newHashMap());
       } else {
         logContents = ThriftBinaryCodec.decode(FileLogContents.class, Files.toByteArray(logFile));

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/8bb538f1/src/test/java/com/twitter/aurora/scheduler/log/testing/FileLogTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/com/twitter/aurora/scheduler/log/testing/FileLogTest.java b/src/test/java/com/twitter/aurora/scheduler/log/testing/FileLogTest.java
new file mode 100644
index 0000000..40eafd8
--- /dev/null
+++ b/src/test/java/com/twitter/aurora/scheduler/log/testing/FileLogTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2013 Twitter, Inc.
+ *
+ * Licensed 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.
+ */
+package com.twitter.aurora.scheduler.log.testing;
+
+import java.io.File;
+import java.io.IOException;
+
+import com.google.common.io.Files;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertNotNull;
+
+public class FileLogTest {
+
+  private File tempDir;
+  private File testingLogFile;
+
+  @Before
+  public void setUp() {
+    tempDir = Files.createTempDir();
+    testingLogFile = new File(tempDir.getAbsolutePath(), "/log_file");
+  }
+
+  @After
+  public void tearDown() {
+    testingLogFile.delete();
+    tempDir.delete();
+  }
+
+  @Test
+  public void testNewFile() throws IOException {
+    FileLog log = new FileLog(testingLogFile);
+    assertNotNull(log.open());
+  }
+
+  @Test
+  public void testEmptyFile() throws IOException {
+    testingLogFile.createNewFile();
+    FileLog log = new FileLog(testingLogFile);
+    assertNotNull(log.open());
+  }
+}


Mime
View raw message