Skip to content

Conversation

@robfrank
Copy link
Collaborator

@robfrank robfrank commented Oct 3, 2025

This pull request adds comprehensive documentation and analysis regarding composite index bugs, their root causes, and the fixes or ongoing work in ArcadeDB. The main focus is on two classes of issues: (1) handling DELETE + CREATE operations with the same composite key in a single transaction, and (2) correctly updating composite indexes when a field is changed and then reverted to its original value across transactions. The documentation details root causes, solution strategies, implementation details, and test results.

Composite Index Bug Analysis and Fix Documentation:

DELETE + CREATE in Same Transaction (Issue #2590, FIXED):

  • Added a detailed analysis (2590-composite-index-analysis.md) explaining how the transaction context previously lost track of deleted RIDs when a REMOVE operation was overwritten by REPLACE, leading to uniqueness validation failures and DuplicatedKeyExceptions. The implemented fix introduces a separate deletedEntries map in TransactionIndexContext.java to track deleted RIDs independently, ensuring correct validation and passing all related tests. [1] [2]

UPDATE to Original Value Across Transactions (PARTIAL, Ongoing):

  • Added deep analysis (COMPOSITE_INDEX_REPLACE_BUG_ANALYSIS.md) of a bug where updating an indexed field back to a previous value causes the index to lose the entry, making the record invisible to index-based queries. The analysis identifies that the transaction context correctly tracks operations, but the underlying LSM tree index may mishandle tombstones (deletion markers) and REPLACE operations, leading to the bug. Several fix options and next steps are outlined, with ongoing investigation into LSM tree behavior. [1] [2]

Codebase and Test Changes:

TransactionIndexContext Enhancements:

  • Introduced deletedEntries and removedRidsPerIndex maps to track deleted RIDs and removed RIDs per index, respectively, in TransactionIndexContext.java. Enhanced addIndexKeyLock() logic for correct operation conversion and added extensive debugging/logging. [1] [2]

Testing and Documentation:

  • Created new minimal reproduction tests and documentation files (SimpleUpdateIndexTest.java, UPDATE_INDEX_BUG_ANALYSIS.md, COMPOSITE_INDEX_UPDATE_STATUS.md) to track status, test results, and ongoing debugging efforts. [1] [2]

Summary of Most Important Changes:

Documentation and Analysis:

  • Added 2590-composite-index-analysis.md and COMPOSITE_INDEX_REPLACE_BUG_ANALYSIS.md for in-depth root cause analysis, solution design, and implementation details for composite index bugs. [1] [2]
  • Created COMPOSITE_INDEX_UPDATE_STATUS.md to track progress, test results, and next steps for composite index fixes.

Codebase Enhancements:

  • Enhanced TransactionIndexContext.java with new fields and logic to preserve deleted RID information and correctly handle ADD→REPLACE operation conversions for unique composite indexes

@robfrank robfrank self-assigned this Oct 3, 2025
@robfrank robfrank added the do not merge The PR is not ready label Oct 3, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @robfrank, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly advances the stability of ArcadeDB's composite indexing by addressing a critical bug related to DELETE and CREATE operations within the same transaction. It also provides a thorough, multi-document analysis of another high-severity bug concerning index updates where a field is reverted to a previous value, outlining root causes, hypotheses, and future investigation steps. The changes include core logic enhancements in the transaction index context and the addition of comprehensive test cases and documentation to support ongoing debugging and verification efforts.

Highlights

  • Composite Index Bug Fix (DELETE + CREATE): Resolved an issue where DELETE followed by CREATE with the same composite key in a single transaction incorrectly threw a DuplicatedKeyException. The fix involves separately tracking deleted RIDs in TransactionIndexContext.java.
  • Deep Analysis of UPDATE Bug: Provided extensive documentation and analysis (COMPOSITE_INDEX_REPLACE_BUG_ANALYSIS.md, UPDATE_INDEX_BUG_ANALYSIS.md) for a critical bug where updating an indexed field back to its original value across transactions causes the index to lose the entry. This bug is still under investigation.
  • Enhanced Transaction Index Context: TransactionIndexContext.java was enhanced with new maps (deletedEntries, removedRidsPerIndex) and logic to correctly manage index operations and preserve deleted RID information during complex transaction scenarios.
  • New Test Cases & Documentation: Introduced several new test files (SimpleUpdateIndexTest.java, DebugUpdateIndexTest.java, DebugUpdateIndexTest3.java) to reproduce and debug composite index issues, along with status tracking documentation (COMPOSITE_INDEX_UPDATE_STATUS.md).
  • JSON Serialization Demo: Added a demonstration class (Issue2497Demo.java) to showcase a fix for JSON empty array serialization (Issue Bug: Insert fails with JSON content containing empty array #2497), ensuring Object[] arrays are correctly serialized as JSON arrays.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds comprehensive documentation and several new tests related to composite index bugs. The analysis provided in the markdown files is thorough and valuable for understanding the issues. However, there are a few points to address. The core logic changes in TransactionIndexContext.java, which are detailed in the pull request description, appear to be missing from the provided file changes. This makes a complete review of the fix impossible. Additionally, some of the new tests are named as 'Debug' tests and include assertions that will always fail, suggesting they are not ready for merging. There is also an unrelated file, Issue2497Demo.java, which should ideally be moved to a separate pull request to keep this one focused. Please see the specific comments for more details.

assertThat(true).isTrue();
} else {
System.out.println("NOT FOUND! Bug confirmed.");
assertThat(false).as("Should find the PENDING record").isTrue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This assertion assertThat(false).as("Should find the PENDING record").isTrue() will always fail. Tests that are designed to fail should not be merged into the main branch as they will break the build. This test should be fixed to pass or removed if it's only for temporary debugging.

values.remove(entry); // Remove the REMOVE operation
// v stays as ADD
} else {
// REPLACE EXISTENT WITH THIS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a typo in the comment. EXISTENT should be EXISTING.

Suggested change
// REPLACE EXISTENT WITH THIS
// REPLACE EXISTING WITH THIS


## Files Modified

1. `/Users/frank/projects/arcade/arcadedb/engine/src/main/java/com/arcadedb/database/TransactionIndexContext.java`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The file path is an absolute local path. For portability and to avoid leaking user-specific information, it should be relative to the repository root. This also applies to other absolute paths in this file, such as on line 242.

Suggested change
1. `/Users/frank/projects/arcade/arcadedb/engine/src/main/java/com/arcadedb/database/TransactionIndexContext.java`
1. `engine/src/main/java/com/arcadedb/database/TransactionIndexContext.java`

## Root Cause Analysis

### Location
**File**: `/Users/frank/projects/arcade/arcadedb/engine/src/main/java/com/arcadedb/database/TransactionIndexContext.java`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The file path is an absolute local path. It should be relative to the repository root to be useful for all contributors. This also applies to other absolute paths in this file, such as on lines 245 and 246.

Suggested change
**File**: `/Users/frank/projects/arcade/arcadedb/engine/src/main/java/com/arcadedb/database/TransactionIndexContext.java`
**File**: `engine/src/main/java/com/arcadedb/database/TransactionIndexContext.java`

* Demonstration class for Issue #2497 - JSON empty array serialization fix.
* This class shows the before/after behavior of Object[] array serialization.
*/
public class Issue2497Demo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file Issue2497Demo.java appears to be a demonstration for a JSON serialization issue (#2497), which seems unrelated to the main focus of this pull request on composite index bugs. To maintain a clean and focused commit history, it would be better to move this file and its related changes to a separate pull request.

@codacy-production
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.17%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (75fec88) 72872 46256 63.48%
Head commit (4f0bcf2) 72872 (+0) 46130 (-126) 63.30% (-0.17%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#2593) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@robfrank robfrank closed this Oct 29, 2025
@robfrank robfrank deleted the fix/2590-composite-index-delete-create branch October 29, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge The PR is not ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants