Skip to content

Commit a93ff93

Browse files
timwtglman
authored andcommitted
Reliably detect distributed plugin enabled.
Use server metadata to detect if distributed plugin is enabled, avoiding races between database access and distributed plugin startup.
1 parent 2ca94eb commit a93ff93

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

distributed/src/main/java/com/orientechnologies/orient/distributed/db/OrientDBDistributed.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import com.orientechnologies.orient.core.db.ODatabasePoolInternal;
1717
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
1818
import com.orientechnologies.orient.core.db.ODatabaseSession;
19+
import com.orientechnologies.orient.core.db.ODatabaseTask;
20+
import com.orientechnologies.orient.core.db.ODatabaseType;
1921
import com.orientechnologies.orient.core.db.OSharedContext;
2022
import com.orientechnologies.orient.core.db.OSharedContextEmbedded;
2123
import com.orientechnologies.orient.core.db.OSystemDatabase;
@@ -108,10 +110,12 @@ public synchronized ODistributedPlugin getPlugin() {
108110
return plugin;
109111
}
110112

113+
private boolean isDistributedPluginEnabled() {
114+
return server.isDistributedPluginEnabled();
115+
}
116+
111117
protected OSharedContext createSharedContext(OAbstractPaginatedStorage storage) {
112-
if (OSystemDatabase.SYSTEM_DB_NAME.equals(storage.getName())
113-
|| plugin == null
114-
|| !plugin.isEnabled()) {
118+
if (!isDistributedPluginEnabled() || OSystemDatabase.SYSTEM_DB_NAME.equals(storage.getName())) {
115119
return new OSharedContextEmbedded(storage, this);
116120
}
117121
return new OSharedContextDistributed(storage, this);
@@ -120,9 +124,7 @@ protected OSharedContext createSharedContext(OAbstractPaginatedStorage storage)
120124
protected ODatabaseDocumentEmbedded newSessionInstance(
121125
OAbstractPaginatedStorage storage, OrientDBConfig config, OSharedContext sharedContext) {
122126
ODatabaseDocumentEmbedded embedded;
123-
if (OSystemDatabase.SYSTEM_DB_NAME.equals(storage.getName())
124-
|| plugin == null
125-
|| !plugin.isEnabled()) {
127+
if (!isDistributedPluginEnabled() || OSystemDatabase.SYSTEM_DB_NAME.equals(storage.getName())) {
126128
embedded = new ODatabaseDocumentEmbedded(storage);
127129
embedded.init(config, sharedContext);
128130
} else {
@@ -137,9 +139,7 @@ protected ODatabaseDocumentEmbedded newSessionInstance(
137139
protected ODatabaseDocumentEmbedded newCreateSessionInstance(
138140
OAbstractPaginatedStorage storage, OrientDBConfig config, OSharedContext sharedContext) {
139141
ODatabaseDocumentEmbedded embedded;
140-
if (OSystemDatabase.SYSTEM_DB_NAME.equals(storage.getName())
141-
|| plugin == null
142-
|| !plugin.isEnabled()) {
142+
if (!isDistributedPluginEnabled() || OSystemDatabase.SYSTEM_DB_NAME.equals(storage.getName())) {
143143
embedded = new ODatabaseDocumentEmbedded(storage);
144144
embedded.internalCreate(config, getOrCreateSharedContext(storage));
145145
} else {
@@ -153,9 +153,7 @@ protected ODatabaseDocumentEmbedded newCreateSessionInstance(
153153
protected ODatabaseDocumentEmbedded newPooledSessionInstance(
154154
ODatabasePoolInternal pool, OAbstractPaginatedStorage storage, OSharedContext sharedContext) {
155155
ODatabaseDocumentEmbedded embedded;
156-
if (OSystemDatabase.SYSTEM_DB_NAME.equals(storage.getName())
157-
|| plugin == null
158-
|| !plugin.isEnabled()) {
156+
if (!isDistributedPluginEnabled() || OSystemDatabase.SYSTEM_DB_NAME.equals(storage.getName())) {
159157
embedded = new ODatabaseDocumentEmbeddedPooled(pool, storage);
160158
embedded.init(pool.getConfig(), getOrCreateSharedContext(storage));
161159
} else {

0 commit comments

Comments
 (0)