GeezerVison is showing github.com — Fixed schema and graph operations executed on a replica server (#205) · humemai/arcadedb-embedded-python@a40baea
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings engine/src/main/java/com/arcadedb main/java/com/arcadedb/server/ha test/java/com/arcadedb/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/database/EmbeddedDatabase.java +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1444,6 +1444,10 @@ public void setWrapper(final String name, final Object instance) { | 1444 | 1444 | this.wrappers.put(name, instance); | 1445 | 1445 | } | 1446 | 1446 |
| | 1447 | + public QueryEngineManager getQueryEngineManager() { | | 1448 | + return queryEngineManager; | | 1449 | + } | | 1450 | + | 1447 | 1451 | public void saveConfiguration() throws IOException { | 1448 | 1452 | FileUtils.writeFile(configurationFile, configuration.toJSON()); | 1449 | 1453 | } | |
Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/database/TransactionContext.java +32-14Lines changed: 32 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 33 | 33 | import com.arcadedb.index.Index; | 34 | 34 | import com.arcadedb.index.lsm.LSMTreeIndexAbstract; | 35 | 35 | import com.arcadedb.log.LogManager; | 36 | | -import com.arcadedb.utility.Pair; | 37 | 36 |
| 38 | 37 | import java.io.*; | 39 | 38 | import java.util.*; | @@ -70,6 +69,16 @@ public class TransactionContext implements Transaction { | 70 | 69 |
| 71 | 70 | public enum STATUS {INACTIVE, BEGUN, COMMIT_1ST_PHASE, COMMIT_2ND_PHASE} | 72 | 71 |
| | 72 | + public class TransactionPhase1 { | | 73 | + public final Binary result; | | 74 | + public final List<MutablePage> modifiedPages; | | 75 | + | | 76 | + public TransactionPhase1(final Binary result, final List<MutablePage> modifiedPages) { | | 77 | + this.result = result; | | 78 | + this.modifiedPages = modifiedPages; | | 79 | + } | | 80 | + } | | 81 | + | 73 | 82 | public TransactionContext(final DatabaseInternal database) { | 74 | 83 | this.database = database; | 75 | 84 | this.walFlush = WALFile.getWALFlushType(database.getConfiguration().getValueAsInteger(GlobalConfiguration.TX_WAL_FLUSH)); | @@ -99,17 +108,17 @@ public Binary commit() { | 99 | 108 | if (status != STATUS.BEGUN) | 100 | 109 | throw new TransactionException("Transaction already in commit phase"); | 101 | 110 |
| 102 | | - final Pair<Binary, List<MutablePage>> changes = commit1stPhase(true); | | 111 | + final TransactionPhase1 phase1 = commit1stPhase(true); | 103 | 112 |
| 104 | | - if (changes != null) | 105 | | - commit2ndPhase(changes); | | 113 | + if (phase1 != null) | | 114 | + commit2ndPhase(phase1); | 106 | 115 | else | 107 | 116 | reset(); | 108 | 117 |
| 109 | 118 | if (database.getSchema().getEmbedded().isDirty()) | 110 | 119 | database.getSchema().getEmbedded().saveConfiguration(); | 111 | 120 |
| 112 | | - return changes != null ? changes.getFirst() : null; | | 121 | + return phase1 != null ? phase1.result : null; | 113 | 122 | } | 114 | 123 |
| 115 | 124 | public Record getRecordFromCache(final RID rid) { | @@ -377,6 +386,9 @@ public void commitFromReplica(final WALFile.WALTransaction buffer, | 377 | 386 | indexChanges.setKeys(keysTx); | 378 | 387 | indexChanges.addFilesToLock(modifiedFiles); | 379 | 388 |
| | 389 | + final int dictionaryFileId = database.getSchema().getDictionary().getId(); | | 390 | + boolean dictionaryModified = false; | | 391 | + | 380 | 392 | for (WALFile.WALPage p : buffer.pages) { | 381 | 393 | final PaginatedFile file = database.getFileManager().getFile(p.fileId); | 382 | 394 | final int pageSize = file.getPageSize(); | @@ -396,10 +408,16 @@ public void commitFromReplica(final WALFile.WALTransaction buffer, | 396 | 408 | newPageCounters.put(pageId.getFileId(), pageId.getPageNumber() + 1); | 397 | 409 | } else | 398 | 410 | modifiedPages.put(pageId, page); | | 411 | + | | 412 | + if (!dictionaryModified && dictionaryFileId == pageId.getFileId()) | | 413 | + dictionaryModified = true; | 399 | 414 | } | 400 | 415 |
| 401 | 416 | database.commit(); | 402 | 417 |
| | 418 | + if (dictionaryModified) | | 419 | + database.getSchema().getDictionary().reload(); | | 420 | + | 403 | 421 | } catch (ConcurrentModificationException e) { | 404 | 422 | rollback(); | 405 | 423 | throw e; | @@ -412,7 +430,7 @@ public void commitFromReplica(final WALFile.WALTransaction buffer, | 412 | 430 | /** | 413 | 431 | * Locks the files in order, then checks all the pre-conditions. | 414 | 432 | */ | 415 | | - public Pair<Binary, List<MutablePage>> commit1stPhase(final boolean isLeader) { | | 433 | + public TransactionPhase1 commit1stPhase(final boolean isLeader) { | 416 | 434 | if (status == STATUS.INACTIVE) | 417 | 435 | throw new TransactionException("Transaction not started"); | 418 | 436 |
| @@ -453,7 +471,6 @@ public Pair<Binary, List<MutablePage>> commit1stPhase(final boolean isLeader) { | 453 | 471 |
| 454 | 472 | // CHECK THE VERSIONS FIRST | 455 | 473 | final List<MutablePage> pages = new ArrayList<>(); | 456 | | - | 457 | 474 | final PageManager pageManager = database.getPageManager(); | 458 | 475 |
| 459 | 476 | for (final Iterator<MutablePage> it = modifiedPages.values().iterator(); it.hasNext(); ) { | @@ -481,13 +498,11 @@ public Pair<Binary, List<MutablePage>> commit1stPhase(final boolean isLeader) { | 481 | 498 |
| 482 | 499 | if (useWAL) { | 483 | 500 | txId = database.getTransactionManager().getNextTransactionId(); | 484 | | - | 485 | | - LogManager.instance().log(this, Level.FINE, "Creating buffer for TX %d (threadId=%d)", null, txId, Thread.currentThread().getId()); | 486 | | - | | 501 | + //LogManager.instance().log(this, Level.FINE, "Creating buffer for TX %d (threadId=%d)", null, txId, Thread.currentThread().getId()); | 487 | 502 | result = database.getTransactionManager().createTransactionBuffer(txId, pages); | 488 | 503 | } | 489 | 504 |
| 490 | | - return new Pair<>(result, pages); | | 505 | + return new TransactionPhase1(result, pages); | 491 | 506 |
| 492 | 507 | } catch (DuplicatedKeyException | ConcurrentModificationException e) { | 493 | 508 | rollback(); | @@ -499,7 +514,10 @@ public Pair<Binary, List<MutablePage>> commit1stPhase(final boolean isLeader) { | 499 | 514 | } | 500 | 515 | } | 501 | 516 |
| 502 | | - public void commit2ndPhase(final Pair<Binary, List<MutablePage>> changes) { | | 517 | + public void commit2ndPhase(final TransactionContext.TransactionPhase1 changes) { | | 518 | + if (changes == null) | | 519 | + return; | | 520 | + | 503 | 521 | if (database.getMode() == PaginatedFile.MODE.READ_ONLY) | 504 | 522 | throw new TransactionException("Cannot commit changes because the database is open in read-only mode"); | 505 | 523 |
| @@ -511,9 +529,9 @@ public void commit2ndPhase(final Pair<Binary, List<MutablePage>> changes) { | 511 | 529 | final PageManager pageManager = database.getPageManager(); | 512 | 530 |
| 513 | 531 | try { | 514 | | - if (changes.getFirst() != null) | | 532 | + if (changes.result != null) | 515 | 533 | // WRITE TO THE WAL FIRST | 516 | | - database.getTransactionManager().writeTransactionToWAL(changes.getSecond(), walFlush, txId, changes.getFirst()); | | 534 | + database.getTransactionManager().writeTransactionToWAL(changes.modifiedPages, walFlush, txId, changes.result); | 517 | 535 |
| 518 | 536 | // AT THIS POINT, LOCK + VERSION CHECK, THERE IS NO NEED TO MANAGE ROLLBACK BECAUSE THERE CANNOT BE CONCURRENT TX THAT UPDATE THE SAME PAGE CONCURRENTLY | 519 | 537 | // UPDATE PAGE COUNTER FIRST | |
Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/index/IndexFactory.java +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 | import com.arcadedb.index.lsm.LSMTreeIndexAbstract; | 21 | 21 | import com.arcadedb.schema.Type; | 22 | 22 |
| 23 | | -import java.io.*; | 24 | 23 | import java.util.*; | 25 | 24 |
| 26 | 25 | public class IndexFactory { | @@ -32,7 +31,7 @@ public void register(final String type, final IndexFactoryHandler handler) { | 32 | 31 |
| 33 | 32 | public IndexInternal createIndex(final String indexType, final DatabaseInternal database, final String indexName, final boolean unique, final String filePath, | 34 | 33 | final PaginatedFile.MODE mode, final Type[] keyTypes, final int pageSize, final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, | 35 | | - final Index.BuildIndexCallback callback) throws IOException { | | 34 | + final Index.BuildIndexCallback callback) { | 36 | 35 | final IndexFactoryHandler handler = map.get(indexType); | 37 | 36 |
| 38 | 37 | if (handler == null) | |
Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/index/IndexFactoryHandler.java +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 | import com.arcadedb.index.lsm.LSMTreeIndexAbstract; | 21 | 21 | import com.arcadedb.schema.Type; | 22 | 22 |
| 23 | | -import java.io.*; | 24 | | - | 25 | 23 | public interface IndexFactoryHandler { | 26 | 24 | IndexInternal create(DatabaseInternal database, String name, boolean unique, String filePath, PaginatedFile.MODE mode, Type[] keyTypes, int pageSize, | 27 | | - LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, Index.BuildIndexCallback callback) throws IOException; | | 25 | + LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, Index.BuildIndexCallback callback); | 28 | 26 | } |
Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/index/lsm/LSMTreeFullTextIndex.java +3-8Lines changed: 3 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -65,8 +65,7 @@ public class LSMTreeFullTextIndex implements Index, IndexInternal { | 65 | 65 | public static class IndexFactoryHandler implements com.arcadedb.index.IndexFactoryHandler { | 66 | 66 | @Override | 67 | 67 | public IndexInternal create(final DatabaseInternal database, final String name, final boolean unique, final String filePath, final PaginatedFile.MODE mode, | 68 | | - final Type[] keyTypes, final int pageSize, final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, final BuildIndexCallback callback) | 69 | | - throws IOException { | | 68 | + final Type[] keyTypes, final int pageSize, final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, final BuildIndexCallback callback) { | 70 | 69 | return new LSMTreeFullTextIndex(database, name, filePath, mode, pageSize, callback); | 71 | 70 | } | 72 | 71 | } | @@ -85,12 +84,8 @@ public PaginatedComponent createOnLoad(final DatabaseInternal database, final St | 85 | 84 | */ | 86 | 85 | public LSMTreeFullTextIndex(final DatabaseInternal database, final String name, final String filePath, final PaginatedFile.MODE mode, final int pageSize, | 87 | 86 | final BuildIndexCallback callback) { | 88 | | - try { | 89 | | - analyzer = new StandardAnalyzer(); | 90 | | - underlyingIndex = new LSMTreeIndex(database, name, false, filePath, mode, new Type[] { Type.STRING }, pageSize, LSMTreeIndexAbstract.NULL_STRATEGY.ERROR); | 91 | | - } catch (IOException e) { | 92 | | - throw new IndexException("Cannot create search engine (error=" + e + ")", e); | 93 | | - } | | 87 | + analyzer = new StandardAnalyzer(); | | 88 | + underlyingIndex = new LSMTreeIndex(database, name, false, filePath, mode, new Type[] { Type.STRING }, pageSize, LSMTreeIndexAbstract.NULL_STRATEGY.ERROR); | 94 | 89 | } | 95 | 90 |
| 96 | 91 | /** | |
Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/index/lsm/LSMTreeIndex.java +8-5Lines changed: 8 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,8 +67,7 @@ public class LSMTreeIndex implements RangeIndex, IndexInternal { | 67 | 67 | public static class IndexFactoryHandler implements com.arcadedb.index.IndexFactoryHandler { | 68 | 68 | @Override | 69 | 69 | public IndexInternal create(final DatabaseInternal database, final String name, final boolean unique, final String filePath, final PaginatedFile.MODE mode, | 70 | | - final Type[] keyTypes, final int pageSize, final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, final BuildIndexCallback callback) | 71 | | - throws IOException { | | 70 | + final Type[] keyTypes, final int pageSize, final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, final BuildIndexCallback callback) { | 72 | 71 | return new LSMTreeIndex(database, name, unique, filePath, mode, keyTypes, pageSize, nullStrategy); | 73 | 72 | } | 74 | 73 | } | @@ -99,9 +98,13 @@ public PaginatedComponent createOnLoad(final DatabaseInternal database, final St | 99 | 98 | * Called at creation time. | 100 | 99 | */ | 101 | 100 | public LSMTreeIndex(final DatabaseInternal database, final String name, final boolean unique, String filePath, final PaginatedFile.MODE mode, | 102 | | - final Type[] keyTypes, final int pageSize, final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy) throws IOException { | 103 | | - this.name = name; | 104 | | - this.mutable = new LSMTreeIndexMutable(this, database, name, unique, filePath, mode, keyTypes, pageSize, nullStrategy); | | 101 | + final Type[] keyTypes, final int pageSize, final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy) { | | 102 | + try { | | 103 | + this.name = name; | | 104 | + this.mutable = new LSMTreeIndexMutable(this, database, name, unique, filePath, mode, keyTypes, pageSize, nullStrategy); | | 105 | + } catch (IOException e) { | | 106 | + throw new IndexException("Error on creating index '" + name + "'", e); | | 107 | + } | 105 | 108 | } | 106 | 109 |
| 107 | 110 | /** | |
Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/log/DefaultLogger.java +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -69,13 +69,15 @@ public void installCustomFormatter() { | 69 | 69 | } | 70 | 70 | } | 71 | 71 |
| 72 | | - public void log(final Object requester, final Level level, String message, final Throwable exception, final String context, final Object arg1, | | 72 | + public void log(final Object requester, Level level, String message, final Throwable exception, final String context, final Object arg1, | 73 | 73 | final Object arg2, final Object arg3, final Object arg4, final Object arg5, final Object arg6, final Object arg7, final Object arg8, final Object arg9, | 74 | 74 | final Object arg10, final Object arg11, final Object arg12, final Object arg13, final Object arg14, final Object arg15, final Object arg16, | 75 | 75 | final Object arg17) { | 76 | 76 | if (message == null) | 77 | 77 | return; | 78 | 78 |
| | 79 | + //level = Level.SEVERE; | | 80 | + | 79 | 81 | final String requesterName; | 80 | 82 | if (requester instanceof String) | 81 | 83 | requesterName = (String) requester; | |
Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/query/QueryEngine.java +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 | import java.util.*; | 22 | 22 |
| 23 | 23 | public interface QueryEngine { | | 24 | + interface AnalyzedQuery { | | 25 | + boolean isIdempotent(); | | 26 | + | | 27 | + boolean isDDL(); | | 28 | + } | | 29 | + | 24 | 30 | interface QueryEngineFactory { | 25 | 31 | boolean isAvailable(); | 26 | 32 |
| @@ -29,6 +35,8 @@ interface QueryEngineFactory { | 29 | 35 | QueryEngine getInstance(DatabaseInternal database); | 30 | 36 | } | 31 | 37 |
| | 38 | + AnalyzedQuery analyze(String query); | | 39 | + | 32 | 40 | ResultSet query(String query, Map<String, Object> parameters); | 33 | 41 |
| 34 | 42 | ResultSet query(String query, Object... parameters); | |
Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/query/cypher/CypherQueryEngine.java +21-9Lines changed: 21 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 25 | 25 | import com.arcadedb.query.sql.executor.Result; | 26 | 26 | import com.arcadedb.query.sql.executor.ResultInternal; | 27 | 27 | import com.arcadedb.query.sql.executor.ResultSet; | 28 | | -import java.lang.reflect.InvocationTargetException; | 29 | 28 |
| 30 | | -import java.util.HashMap; | 31 | | -import java.util.List; | 32 | | -import java.util.Map; | 33 | | -import java.util.Set; | 34 | | -import java.util.logging.Level; | 35 | | -import java.util.stream.Collectors; | | 29 | +import java.lang.reflect.*; | | 30 | +import java.util.*; | | 31 | +import java.util.logging.*; | | 32 | +import java.util.stream.*; | 36 | 33 |
| 37 | 34 | public class CypherQueryEngine implements QueryEngine { | 38 | 35 | private static final String ENGINE_NAME = "cypher-engine"; | 39 | | - private final Object arcadeGraph; | | 36 | + private final Object arcadeGraph; | 40 | 37 |
| 41 | 38 | public static class CypherQueryEngineFactory implements QueryEngineFactory { | 42 | | - private static Boolean available = null; | | 39 | + private static Boolean available = null; | 43 | 40 | private static Class<?> arcadeGraphClass; | 44 | 41 | private static Class<?> arcadeCypherClass; | 45 | 42 |
| @@ -84,6 +81,21 @@ protected CypherQueryEngine(final Object arcadeGraph) { | 84 | 81 | this.arcadeGraph = arcadeGraph; | 85 | 82 | } | 86 | 83 |
| | 84 | + @Override | | 85 | + public AnalyzedQuery analyze(String query) { | | 86 | + return new AnalyzedQuery() { | | 87 | + @Override | | 88 | + public boolean isIdempotent() { | | 89 | + return false; | | 90 | + } | | 91 | + | | 92 | + @Override | | 93 | + public boolean isDDL() { | | 94 | + return false; | | 95 | + } | | 96 | + }; | | 97 | + } | | 98 | + | 87 | 99 | @Override | 88 | 100 | public ResultSet query(final String query, final Map<String, Object> parameters) { | 89 | 101 | return command(query, parameters); | |
Collapse file Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/query/gremlin/GremlinQueryEngine.java +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -107,4 +107,20 @@ public ResultSet command(final String query, final Object... parameters) { | 107 | 107 | map.put((String) parameters[i], parameters[i + 1]); | 108 | 108 | return command(query, map); | 109 | 109 | } | | 110 | + | | 111 | + @Override | | 112 | + public AnalyzedQuery analyze(String query) { | | 113 | + return new AnalyzedQuery() { | | 114 | + @Override | | 115 | + public boolean isIdempotent() { | | 116 | + return false; | | 117 | + } | | 118 | + | | 119 | + @Override | | 120 | + public boolean isDDL() { | | 121 | + return false; | | 122 | + } | | 123 | + }; | | 124 | + } | | 125 | + | 110 | 126 | } |
|