|
25 | 25 | import com.orientechnologies.orient.core.db.OrientDBEmbedded; |
26 | 26 | import com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded; |
27 | 27 | import com.orientechnologies.orient.core.exception.ODatabaseException; |
| 28 | +import com.orientechnologies.orient.core.metadata.security.auth.OAuthenticationInfo; |
28 | 29 | import com.orientechnologies.orient.core.storage.OStorage; |
29 | 30 | import com.orientechnologies.orient.core.storage.disk.OLocalPaginatedStorage; |
30 | 31 | import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage; |
|
58 | 59 | import java.util.Map.Entry; |
59 | 60 | import java.util.Set; |
60 | 61 | import java.util.concurrent.ConcurrentHashMap; |
| 62 | +import java.util.concurrent.CountDownLatch; |
| 63 | +import java.util.concurrent.TimeUnit; |
61 | 64 |
|
62 | 65 | /** Created by tglman on 08/08/17. */ |
63 | 66 | public class OrientDBDistributed extends OrientDBEmbedded implements OServerAware { |
64 | 67 |
|
65 | 68 | private volatile OServer server; |
66 | 69 | private volatile ODistributedPlugin plugin; |
| 70 | + private final CountDownLatch pluginStartupLatch = new CountDownLatch(1); |
67 | 71 | protected final ConcurrentHashMap<String, ODistributedDatabaseImpl> databases = |
68 | 72 | new ConcurrentHashMap<String, ODistributedDatabaseImpl>(); |
69 | 73 | protected final ConcurrentHashMap<String, ODistributedConfigurationManager> configurations = |
@@ -103,10 +107,33 @@ public void loadAllDatabases() { |
103 | 107 | } |
104 | 108 | } |
105 | 109 |
|
106 | | - public synchronized ODistributedPlugin getPlugin() { |
107 | | - if (plugin == null) { |
108 | | - if (server != null && server.isActive()) plugin = server.getPlugin("cluster"); |
| 110 | + private void waitForPluginStartup() { |
| 111 | + if (isDistributedPluginEnabled() && plugin == null) { |
| 112 | + try { |
| 113 | + OLogManager.instance().info(this, "Waiting for plugin startup"); |
| 114 | + if (!pluginStartupLatch.await(10, TimeUnit.SECONDS)) { |
| 115 | + throw new OOfflineNodeException("Distributed manager is offline on " + server.getServerId()); |
| 116 | + } |
| 117 | + OLogManager.instance().info(this, "Plugin startup complete"); |
| 118 | + } catch (InterruptedException ignored) { |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + public void setPlugin(ODistributedPlugin plugin) { |
| 124 | + OLogManager.instance().info(this, "Setting plugin"); |
| 125 | + this.plugin = plugin; |
| 126 | + this.pluginStartupLatch.countDown(); |
109 | 127 | } |
| 128 | + |
| 129 | + public ODistributedPlugin getPlugin() { |
| 130 | + OLogManager.instance() |
| 131 | + .info( |
| 132 | + this, |
| 133 | + "Getting plugin, server?=%s, server.active?=%s", |
| 134 | + server != null, |
| 135 | + server.isActive()); |
| 136 | + waitForPluginStartup(); |
110 | 137 | return plugin; |
111 | 138 | } |
112 | 139 |
|
@@ -164,10 +191,6 @@ protected ODatabaseDocumentEmbedded newPooledSessionInstance( |
164 | 191 | return embedded; |
165 | 192 | } |
166 | 193 |
|
167 | | - public void setPlugin(ODistributedPlugin plugin) { |
168 | | - this.plugin = plugin; |
169 | | - } |
170 | | - |
171 | 194 | public OStorage fullSync(String dbName, InputStream backupStream, OrientDBConfig config) { |
172 | 195 | OAbstractPaginatedStorage storage = null; |
173 | 196 | ODatabaseDocumentEmbedded embedded; |
|
0 commit comments