Added a distributed leadership manager implementation on top of consistent map.
Change-Id: I3f3c6114df72e3ab033ba39c8608ac4ae11e5272
Showing
3 changed files
with
16 additions
and
1 deletions
... | @@ -53,7 +53,7 @@ public class ConsistentMapImpl<K, V> implements ConsistentMap<K, V> { | ... | @@ -53,7 +53,7 @@ public class ConsistentMapImpl<K, V> implements ConsistentMap<K, V> { |
53 | private final DatabaseProxy<String, byte[]> proxy; | 53 | private final DatabaseProxy<String, byte[]> proxy; |
54 | private final Serializer serializer; | 54 | private final Serializer serializer; |
55 | 55 | ||
56 | - private static final int OPERATION_TIMEOUT_MILLIS = 1000; | 56 | + private static final int OPERATION_TIMEOUT_MILLIS = 5000; |
57 | private static final String ERROR_NULL_KEY = "Key cannot be null"; | 57 | private static final String ERROR_NULL_KEY = "Key cannot be null"; |
58 | private static final String ERROR_NULL_VALUE = "Null values are not allowed"; | 58 | private static final String ERROR_NULL_VALUE = "Null values are not allowed"; |
59 | 59 | ... | ... |
... | @@ -17,11 +17,13 @@ | ... | @@ -17,11 +17,13 @@ |
17 | package org.onosproject.store.consistent.impl; | 17 | package org.onosproject.store.consistent.impl; |
18 | 18 | ||
19 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
20 | + | ||
20 | import net.kuujo.copycat.cluster.ClusterConfig; | 21 | import net.kuujo.copycat.cluster.ClusterConfig; |
21 | import net.kuujo.copycat.cluster.Member; | 22 | import net.kuujo.copycat.cluster.Member; |
22 | import net.kuujo.copycat.log.FileLog; | 23 | import net.kuujo.copycat.log.FileLog; |
23 | import net.kuujo.copycat.netty.NettyTcpProtocol; | 24 | import net.kuujo.copycat.netty.NettyTcpProtocol; |
24 | import net.kuujo.copycat.protocol.Consistency; | 25 | import net.kuujo.copycat.protocol.Consistency; |
26 | + | ||
25 | import org.apache.felix.scr.annotations.Activate; | 27 | import org.apache.felix.scr.annotations.Activate; |
26 | import org.apache.felix.scr.annotations.Component; | 28 | import org.apache.felix.scr.annotations.Component; |
27 | import org.apache.felix.scr.annotations.Deactivate; | 29 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -44,6 +46,8 @@ import java.io.IOException; | ... | @@ -44,6 +46,8 @@ import java.io.IOException; |
44 | import java.util.List; | 46 | import java.util.List; |
45 | import java.util.Map; | 47 | import java.util.Map; |
46 | import java.util.Set; | 48 | import java.util.Set; |
49 | +import java.util.concurrent.CountDownLatch; | ||
50 | +import java.util.concurrent.TimeUnit; | ||
47 | import java.util.stream.Collectors; | 51 | import java.util.stream.Collectors; |
48 | 52 | ||
49 | import static org.slf4j.LoggerFactory.getLogger; | 53 | import static org.slf4j.LoggerFactory.getLogger; |
... | @@ -60,6 +64,7 @@ public class DatabaseManager implements StorageService, StorageAdminService { | ... | @@ -60,6 +64,7 @@ public class DatabaseManager implements StorageService, StorageAdminService { |
60 | public static final int COPYCAT_TCP_PORT = 7238; // 7238 = RAFT | 64 | public static final int COPYCAT_TCP_PORT = 7238; // 7238 = RAFT |
61 | private static final String CONFIG_DIR = "../config"; | 65 | private static final String CONFIG_DIR = "../config"; |
62 | private static final String PARTITION_DEFINITION_FILE = "tablets.json"; | 66 | private static final String PARTITION_DEFINITION_FILE = "tablets.json"; |
67 | + private static final int DATABASE_STARTUP_TIMEOUT_SEC = 60; | ||
63 | 68 | ||
64 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 69 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
65 | protected ClusterService clusterService; | 70 | protected ClusterService clusterService; |
... | @@ -131,13 +136,23 @@ public class DatabaseManager implements StorageService, StorageAdminService { | ... | @@ -131,13 +136,23 @@ public class DatabaseManager implements StorageService, StorageAdminService { |
131 | 136 | ||
132 | partitionedDatabase = PartitionedDatabaseManager.create("onos-store", clusterConfig, databaseConfig); | 137 | partitionedDatabase = PartitionedDatabaseManager.create("onos-store", clusterConfig, databaseConfig); |
133 | 138 | ||
139 | + CountDownLatch latch = new CountDownLatch(1); | ||
134 | partitionedDatabase.open().whenComplete((db, error) -> { | 140 | partitionedDatabase.open().whenComplete((db, error) -> { |
135 | if (error != null) { | 141 | if (error != null) { |
136 | log.warn("Failed to open database.", error); | 142 | log.warn("Failed to open database.", error); |
137 | } else { | 143 | } else { |
144 | + latch.countDown(); | ||
138 | log.info("Successfully opened database."); | 145 | log.info("Successfully opened database."); |
139 | } | 146 | } |
140 | }); | 147 | }); |
148 | + try { | ||
149 | + if (!latch.await(DATABASE_STARTUP_TIMEOUT_SEC, TimeUnit.SECONDS)) { | ||
150 | + log.warn("Timeed out watiing for database to initialize."); | ||
151 | + } | ||
152 | + } catch (InterruptedException e) { | ||
153 | + Thread.currentThread().interrupt(); | ||
154 | + log.warn("Failed to complete database initialization."); | ||
155 | + } | ||
141 | log.info("Started"); | 156 | log.info("Started"); |
142 | } | 157 | } |
143 | 158 | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment