Committed by
Gerrit Code Review
ONOS-1673: Fail fast when DatabaseManager does not start up cleanly
Change-Id: I9fcc1c85bb4169681b20df08d69ac8fdcc9d5ddc
Showing
1 changed file
with
6 additions
and
16 deletions
... | @@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableSet; | ... | @@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableSet; |
20 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
21 | import com.google.common.collect.Maps; | 21 | import com.google.common.collect.Maps; |
22 | import com.google.common.collect.Sets; | 22 | import com.google.common.collect.Sets; |
23 | +import com.google.common.util.concurrent.Futures; | ||
23 | 24 | ||
24 | import net.kuujo.copycat.CopycatConfig; | 25 | import net.kuujo.copycat.CopycatConfig; |
25 | import net.kuujo.copycat.cluster.ClusterConfig; | 26 | import net.kuujo.copycat.cluster.ClusterConfig; |
... | @@ -68,7 +69,6 @@ import java.util.List; | ... | @@ -68,7 +69,6 @@ import java.util.List; |
68 | import java.util.Map; | 69 | import java.util.Map; |
69 | import java.util.Set; | 70 | import java.util.Set; |
70 | import java.util.concurrent.CompletableFuture; | 71 | import java.util.concurrent.CompletableFuture; |
71 | -import java.util.concurrent.CountDownLatch; | ||
72 | import java.util.concurrent.ExecutionException; | 72 | import java.util.concurrent.ExecutionException; |
73 | import java.util.concurrent.Executors; | 73 | import java.util.concurrent.Executors; |
74 | import java.util.concurrent.TimeUnit; | 74 | import java.util.concurrent.TimeUnit; |
... | @@ -90,7 +90,6 @@ public class DatabaseManager implements StorageService, StorageAdminService { | ... | @@ -90,7 +90,6 @@ public class DatabaseManager implements StorageService, StorageAdminService { |
90 | public static final String PARTITION_DEFINITION_FILE = "../config/tablets.json"; | 90 | public static final String PARTITION_DEFINITION_FILE = "../config/tablets.json"; |
91 | public static final String BASE_PARTITION_NAME = "p0"; | 91 | public static final String BASE_PARTITION_NAME = "p0"; |
92 | 92 | ||
93 | - private static final int DATABASE_STARTUP_TIMEOUT_SEC = 60; | ||
94 | private static final int RAFT_ELECTION_TIMEOUT_MILLIS = 3000; | 93 | private static final int RAFT_ELECTION_TIMEOUT_MILLIS = 3000; |
95 | private static final int DATABASE_OPERATION_TIMEOUT_MILLIS = 5000; | 94 | private static final int DATABASE_OPERATION_TIMEOUT_MILLIS = 5000; |
96 | 95 | ||
... | @@ -176,27 +175,18 @@ public class DatabaseManager implements StorageService, StorageAdminService { | ... | @@ -176,27 +175,18 @@ public class DatabaseManager implements StorageService, StorageAdminService { |
176 | 175 | ||
177 | partitionedDatabase = new PartitionedDatabase("onos-store", partitions); | 176 | partitionedDatabase = new PartitionedDatabase("onos-store", partitions); |
178 | 177 | ||
179 | - CountDownLatch latch = new CountDownLatch(1); | 178 | + CompletableFuture<Void> status = coordinator.open() |
180 | - | ||
181 | - coordinator.open() | ||
182 | .thenCompose(v -> CompletableFuture.allOf(inMemoryDatabase.open(), partitionedDatabase.open()) | 179 | .thenCompose(v -> CompletableFuture.allOf(inMemoryDatabase.open(), partitionedDatabase.open()) |
183 | .whenComplete((db, error) -> { | 180 | .whenComplete((db, error) -> { |
184 | if (error != null) { | 181 | if (error != null) { |
185 | - log.warn("Failed to create databases.", error); | 182 | + log.error("Failed to initialize database.", error); |
186 | } else { | 183 | } else { |
187 | - latch.countDown(); | 184 | + log.info("Successfully initialized database."); |
188 | - log.info("Successfully created databases."); | ||
189 | } | 185 | } |
190 | })); | 186 | })); |
191 | 187 | ||
192 | - try { | 188 | + Futures.getUnchecked(status); |
193 | - if (!latch.await(DATABASE_STARTUP_TIMEOUT_SEC, TimeUnit.SECONDS)) { | 189 | + |
194 | - log.warn("Timed out waiting for database to initialize."); | ||
195 | - } | ||
196 | - } catch (InterruptedException e) { | ||
197 | - Thread.currentThread().interrupt(); | ||
198 | - log.warn("Failed to complete database initialization."); | ||
199 | - } | ||
200 | transactionManager = new TransactionManager(partitionedDatabase); | 190 | transactionManager = new TransactionManager(partitionedDatabase); |
201 | log.info("Started"); | 191 | log.info("Started"); |
202 | } | 192 | } | ... | ... |
-
Please register or login to post a comment