15
15
*/
16
16
package com .orientechnologies .orient .server .distributed ;
17
17
18
+ import java .io .File ;
19
+ import java .io .FileInputStream ;
20
+ import java .io .FileOutputStream ;
21
+ import java .io .IOException ;
22
+ import java .util .HashMap ;
23
+ import java .util .Map ;
24
+
18
25
import com .orientechnologies .common .log .OLogManager ;
19
26
import com .orientechnologies .common .parser .OSystemVariableResolver ;
20
27
import com .orientechnologies .orient .core .Orient ;
30
37
import com .orientechnologies .orient .server .distributed .conflict .OReplicationConflictResolver ;
31
38
import com .orientechnologies .orient .server .plugin .OServerPluginAbstract ;
32
39
33
- import java .io .File ;
34
- import java .io .FileInputStream ;
35
- import java .io .FileOutputStream ;
36
- import java .io .IOException ;
37
- import java .util .HashMap ;
38
- import java .util .Map ;
39
-
40
40
/**
41
41
* Abstract plugin to manage the distributed environment.
42
42
*
@@ -196,6 +196,7 @@ protected ODocument loadDatabaseConfiguration(final String iDatabaseName, final
196
196
f .read (buffer );
197
197
198
198
final ODocument doc = (ODocument ) new ODocument ().fromJSON (new String (buffer ), "noMap" );
199
+ doc .field ("version" , 0 );
199
200
updateCachedDatabaseConfiguration (iDatabaseName , doc , false );
200
201
return doc ;
201
202
@@ -212,13 +213,14 @@ protected ODocument loadDatabaseConfiguration(final String iDatabaseName, final
212
213
213
214
public boolean updateCachedDatabaseConfiguration (final String iDatabaseName , final ODocument cfg , final boolean iSaveToDisk ) {
214
215
synchronized (cachedDatabaseConfiguration ) {
215
- // final ODocument oldCfg = cachedDatabaseConfiguration.get(iDatabaseName);
216
- // if (oldCfg != null && oldCfg.field("version").equals(cfg.field("version"))) {
217
- // // NO CHANGE, SKIP IT
218
- // OLogManager.instance().debug(this, "Skip saving of distributed configuration file for database '%s' because is unchanged",
219
- // iDatabaseName);
220
- // return false;
221
- // }
216
+ final ODocument oldCfg = cachedDatabaseConfiguration .get (iDatabaseName );
217
+ if (oldCfg != null && (Integer ) oldCfg .field ("version" ) > (Integer ) cfg .field ("version" )) {
218
+ // NO CHANGE, SKIP IT
219
+ OLogManager .instance ().debug (this ,
220
+ "Skip saving of distributed configuration file for database '%s' because is unchanged (version %d)" , iDatabaseName ,
221
+ (Integer ) cfg .field ("version" ));
222
+ return false ;
223
+ }
222
224
223
225
// SAVE IN NODE'S LOCAL RAM
224
226
cachedDatabaseConfiguration .put (iDatabaseName , cfg );
@@ -268,7 +270,6 @@ public ODistributedConfiguration getDatabaseConfiguration(final String iDatabase
268
270
cfg = loadDatabaseConfiguration (iDatabaseName , defaultDatabaseConfigFile );
269
271
if (cfg == null )
270
272
throw new OConfigurationException ("Cannot load default distributed database config file: " + defaultDatabaseConfigFile );
271
- cfg .field ("version" , 0 );
272
273
}
273
274
}
274
275
return new ODistributedConfiguration (cfg );
0 commit comments