GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Application cannot get the newest records submitted by previous commits under async flush mode · Issue #1302 · ArcadeData/arcadedb

Application cannot get the newest records submitted by previous commits under async flush mode #1302

New issue
Copy link
New issue
Copy link
Closed
Closed
Application cannot get the newest records submitted by previous commits under async flush mode#1302
Copy link
Assignees
lvca
Labels
unable to reproducewontfixThis will not be worked onworkaround-provided
Milestone
23.11.1

Description

@HarroYuz
HarroYuz
opened on Nov 6, 2023
Issue body actions

ArcadeDB Version:

ArcadeDB Server v23.9.1 (build //)

OS and JDK Version:

Running on Linux 6.2.16-3-pve - OpenJDK 64-Bit Server VM 21

Expected behavior

Application read the newest record which is submitted by previous commits without concurrent commits under async flush mode.

Actual behavior

Application may read the old record without concurrent commits under async flush mode.

Steps to reproduce

Continuously insert records with large size (property values long string for example) with serveral commits using async flush mode and read them immediately

Additional description

This bug is due to the way modified pages are flushed into files under async flush mode. When asyncFlush transaction is committed, the modified pages are passed to the FlushThread and then recorded in readCache of PageManager, then FlushThread flush the pages into files. This usually works, until large amount of pages are modified continuously. In this case, the readCache may exceed the limit and drop the pages which not yet writen to files. If function loadPage tries to read the dropped page at the same time, it will not find the page in readCache, and will read the old page from the files.

This bug may produce several Exceptions, such as RecordNotFoundException if a page with new records not flushed yet. Moreover, the bug may cause ConcurrentModificationException even if two transactions are submitted by same thread, which is quite confusing. This happens when the latter transaction read a old page of former one to modify, and the new page has been flushed into files when the latter transaction commits. The database found that the version of modified page is different from the one of page in file, so it throws a ConcurrentModificationException.

This is the log when the ConcurrentModificationException is thrown:

2023-10-25 15:00:03.938 SEVER [PageManager] Reached max RAM for page cache. Freeing pages from cache (target=2152628224 current=4305256448 max=4294967296 threadId=41)
2023-10-25 15:00:31.163 SEVER [PageManager] Reached max RAM for page cache. Freeing pages from cache (target=2147483648 current=4294967296 max=4294967296 threadId=41)
2023-10-25 15:00:37.886 SEVER [PageManager] Reached max RAM for page cache. Freeing pages from cache (target=2147483648 current=4294967296 max=4294967296 threadId=41)
2023-10-25 15:00:58.637 SEVER [PageManager] Reached max RAM for page cache. Freeing pages from cache (target=2147483648 current=4294967296 max=4294967296 threadId=41)
2023-10-25 15:00:59.967 SEVER [PageManager] Concurrent modification on page PageId(78/416) in file '_stat_16_camera_number_0.78.65536.v0.bucket' (current v.66 <> database v.67). Please retry the operation (threadId=41)
2023-10-25 15:01:00.489 SEVER [PageManager] Reached max RAM for page cache. Freeing pages from cache (target=2147483648 current=4294967296 max=4294967296 threadId=41)

As for the fix of this bug, maybe check whether the cached page to remove from readCache is flushed into files is an option, or there may be some better choices.

Activity

  1. lvca
    self-assigned this
    on Nov 6, 2023
  2. lvca commented on Nov 6, 2023

    @lvca
    lvca
    on Nov 6, 2023
    Member
    More actions

    Thanks @hjhk555 for the detailed explanation. The read cache contains only immutable pages, so it's fine if they are flushed during page eviction. A transaction should hold the immutable page when is modified to avoid this issue. This should be supported by REPEATABLE_READ isolation mode.

    Questions:

    • Are you using the embedded database or via remote?
    • Have you already tried using database.setTransactionIsolationLevel(REPEATABLE_READ)?
  3. lvca
    added this to the 23.11.1 milestone on Nov 6, 2023
  4. lvca
    added
    waiting for user
    on Nov 6, 2023
  5. HarroYuz commented on Nov 7, 2023

    @HarroYuz
    HarroYuz
    on Nov 7, 2023
    Author
    More actions

    Thank you for your reply.

    I'm using embedded database, and I have tried using database.setTransactionIsolationLevel(REPEATABLE_READ) while this issue still occurred.

    In my opinion, the reason of this issue is that the eviction of immutable pages happens before the pages are flushed. In the interval between page eviction and page flushed, the newest page is stored only in the queue of FlushThread of PageManager.

    When TransactionContext tries to get the page to modify, it calls getPage, and if this page is not in TransactionContext, it calls PageManager.getImmutablePage, where the queue of FlushThread is not looked for.

    This leads to the possibility that the TransactionContext failed to load the newest page.

  6. lvca commented on Nov 7, 2023

    @lvca
    lvca
    on Nov 7, 2023
    Member
    More actions

    @hjhk555 it makes sense to me. Let me check those parts.

  7. lvca
    added a commit that references this issue on Nov 7, 2023

    fix: use flushing page if available instead of loading a page from disk

    f94ed30
  8. lvca commented on Nov 7, 2023

    @lvca
    lvca
    on Nov 7, 2023
    Member
    More actions

    I checked your analysis and it's correct. I general, the user code should be aware of concurrent modification exceptions and manage a retry/reload, but in the case of a single thread, it would be a little counter intuitive.

    I've just pushed a fix but I'm struggling with writing a test case to reproduce the issue.

    @hjhk555 any chance you can help me with writing such a test case?

    This new method in PageManager reuses the page in the queue, ready to be flushed:

     public CachedPage getCachedPageFromMutablePageInQueue(final PageId pageId) {
        final Object[] content = queue.toArray();
        for (int i = 0; i < content.length; i++) {
          final List<MutablePage> pages = (List<MutablePage>) content[i];
          if (pages != null) {
            for (int j = 0; j < pages.size(); j++) {
              final MutablePage page = pages.get(j);
              if (page.getPageId().equals(pageId))
                return new CachedPage(page, true);
            }
          }
        }
        return null;
      }

    It's not very efficient, but it's rare to have many pages in the flush queue, unless of poor write disk performance or large transactions.

  9. lvca commented on Nov 7, 2023

    @lvca
    lvca
    on Nov 7, 2023
    Member
    More actions

    An alternative would be waiting for the page to be flushed and reloading it from the disk.

  10. HarroYuz commented on Nov 8, 2023

    @HarroYuz
    HarroYuz
    on Nov 8, 2023
    Author
    More actions

    For the test case, The data I'm using contains sensitive information, and I haven't found a way to reproduce the issue with generated data, which is a pity.

    And for the code, this issue still happens with the fix. In my point of view, the search order of queue should be opposite, because the newest pages are in the tail of queue. Moreover, the pages polled by function flushPagesFromQueueToDisk is removed from queue, which can lead to this issue since the page requested may among those removed pages.

    Upon analysis above, I tried to fix by save the flushing pages in critical section. The modified code is like this:

    
      private          List<MutablePage>                     flushingPages;
      private          ReentrantLock                         flushingPagesLock = new ReentrantLock();
    
      protected void flushPagesFromQueueToDisk(final long timeout) throws InterruptedException, IOException {
        if (!queue.isEmpty()) {
          flushingPagesLock.lock();
          flushingPages = queue.poll(timeout, TimeUnit.MILLISECONDS);
          flushingPagesLock.unlock();
          
          if (flushingPages == null)
            return;
          
          if (flushingPages.isEmpty())
            // EMPTY PAGES IS A SPECIAL CONTENT FOR SHUTDOWN
            running = false;
          else {
            for (final MutablePage page : flushingPages)
              try {
                pageManager.flushPage(page);
              } catch (final DatabaseMetadataException e) {
                // FILE DELETED, CONTINUE WITH THE NEXT PAGES
                LogManager.instance().log(this, Level.WARNING, "Error on flushing page '%s' to disk", e, page);
              }
          }
          
          flushingPagesLock.lock();
          flushingPages = null;
          flushingPagesLock.unlock();
        }
      }
    
      public CachedPage getCachedPageFromMutablePageInQueue(final PageId pageId) {
        final Object[] content = queue.toArray();
        for (int i = content.length - 1; i >= 0; i--) {
          final List<MutablePage> pages = (List<MutablePage>) content[i];
          if (pages != null) {
            for (int j = 0; j < pages.size(); j++) {
              final MutablePage page = pages.get(j);
              if (page.getPageId().equals(pageId))
                return new CachedPage(page, true);
            }
          }
        }
    
        CachedPage pageInFlushing = null;
        flushingPagesLock.lock();
        if (flushingPages != null) {
          for (MutablePage page : flushingPages) {
            if (page.getPageId().equals(pageId)) {
              pageInFlushing = new CachedPage(page, true);
              break;
            }
          }
        }
        flushingPagesLock.unlock();
    
        return pageInFlushing;
      }
    

    After doing so, the issue does disapper. But I found that the efficiency of async massive inserts even become lower than which of the sync one before, so there may be a better way to deal with this issue.

  11. HarroYuz commented on Nov 8, 2023

    @HarroYuz
    HarroYuz
    on Nov 8, 2023
    Author
    More actions

    Maybe keep the page's version when doing page eviction is a soulution, when page is reload from disk, the version of page can be verified, which should be larger or equal to the one stored(in case of multiple user threads).

  12. lvca commented on Nov 8, 2023

    @lvca
    lvca
    on Nov 8, 2023
    Member
    More actions

    Okay, I'm going to remove my patch then because useless.

    There is not an easy solution without adding locks, and I won't slow down the normal database operations for such a rare use case (so rare I can't find a way to reproduce it) anyway.

    The solution should be that in your user code, you catch the ConcurrentModificationException and repeat the transaction when this happens. After all, this is why we have an MVCC, to catch issues like this and keep the database consistent.

    If you use the transaction method, the transaction is automatically retried (up to 3 times, configurable) in case that case happens.

    db.transaction( () -> {
      final MutableVertex v = database.newVertex("Author");
      v.set("name", "Jay");
      v.set("surname", "Miner");
      v.save();
    });
    
  13. lvca
    added
    unable to reproduce
    on Nov 8, 2023
  14. lvca commented on Nov 14, 2023

    @lvca
    lvca
    on Nov 14, 2023
    Member
    More actions

    Closing this issue because I cannot reproduce it and the provided solution (managing things in a transaction block with auto retry) solves this issue.

  15. lvca
    closed this as completedon Nov 14, 2023
  16. lvca
    added
    wontfixThis will not be worked on
    workaround-provided
    and removed
    waiting for user
    on Nov 14, 2023
  17. mergify
    added a commit that references this issue on Dec 1, 2025

    chore(deps): bump org.codehaus.mojo:versions-maven-plugin from 2.19.1…

    abcb9ff
  18. mergify
    added 2 commits that reference this issue on May 24, 2026

    chore(deps): bump uuid and testcontainers in /e2e-js [skip ci]

    7989577

    chore(deps): bump uuid and testcontainers in /e2e-studio [skip ci]

    07a134b
  19. tae898
    added 4 commits that reference this issue on Jun 28, 2026

    fix: use flushing page if available instead of loading a page from disk

    f4793ea

    chore(deps): bump org.codehaus.mojo:versions-maven-plugin from 2.19.1…

    c39faf2

    chore(deps): bump uuid and testcontainers in /e2e-js [skip ci]

    b3bde1e

    chore(deps): bump uuid and testcontainers in /e2e-studio [skip ci]

    cf0747a
  20. mergify
    added 2 commits that reference this issue on Jun 29, 2026

    chore(deps): update psycopg requirement from >=3.2.13 to >=3.3.4 in /…

    62f3281

    chore(deps): update psycopg-binary requirement from >=3.2.13 to >=3.3…

    6d30d72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @lvca
    lvca

Labels

unable to reproducewontfixThis will not be worked onworkaround-provided

Type

No type

Projects

No projects

    Milestone

    • 23.11.1

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.