core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/OAbstractPaginatedStorage.java
public Set<ORecordId> recordsChangedRecently(final int maxEntries) {
    final SortedSet<ORecordId> result = new TreeSet<>();

    try {
      if (!OGlobalConfiguration.STORAGE_TRACK_CHANGED_RECORDS_IN_WAL.getValueAsBoolean()) {
        throw new IllegalStateException(
            "Cannot find records which were changed starting from provided LSN because tracking of rids of changed records in WAL is switched off, "
                + "to switch it on please set property " + OGlobalConfiguration.STORAGE_TRACK_CHANGED_RECORDS_IN_WAL.getKey()
                + " to the true value, please note that only records"
                + " which are stored after this property was set will be retrieved");
      }

      stateLock.acquireReadLock();
      try {
        if (writeAheadLog == null) {
          OLogManager.instance().warn(this, "No WAL found for database '%s'", name);
          return null;
        }

        OLogSequenceNumber startLsn = writeAheadLog.begin();
        if (startLsn == null) {
          OLogManager.instance().warn(this, "The WAL is empty for database '%s'", name);
          return result;
        }

        final OLogSequenceNumber freezeLSN = startLsn;
        writeAheadLog.addCutTillLimit(freezeLSN);
        try {
          //reread because log may be already truncated
          startLsn = writeAheadLog.begin();
          if (startLsn == null) {
            OLogManager.instance().warn(this, "The WAL is empty for database '%s'", name);
            return result;
          }

          final OLogSequenceNumber endLsn = writeAheadLog.end();
          if (endLsn == null) {
            OLogManager.instance().warn(this, "The WAL is empty for database '%s'", name);
            return result;
          }

          List<OWriteableWALRecord> walRecords = writeAheadLog.read(startLsn, 1_000);
          if (walRecords.isEmpty()) {
            OLogManager.instance()
                .info(this, "Cannot find requested LSN=%s for database sync operation (record in WAL is absent)", startLsn);
            return null;
          }

          // KEEP LAST MAX-ENTRIES TRANSACTIONS' LSN
          final List<OAtomicUnitEndRecord> lastTx = new ArrayList<>(1024);
          readLoop:
          while (!walRecords.isEmpty()) {
            for (final OWriteableWALRecord walRecord : walRecords) {
              final OLogSequenceNumber recordLSN = walRecord.getLsn();
              if (endLsn.compareTo(recordLSN) >= 0) {
                if (walRecord instanceof OAtomicUnitEndRecord) {
                  if (lastTx.size() >= maxEntries) {
                    lastTx.remove(0);
                  }

                  lastTx.add((OAtomicUnitEndRecord) walRecord);
                }
              } else {
                break readLoop;
              }
            }

            walRecords = writeAheadLog.next(walRecords.get(walRecords.size() - 1).getLsn(), 1_000);
          }

          // COLLECT ALL THE MODIFIED RECORDS
          for (final OAtomicUnitEndRecord atomicUnitEndRecord : lastTx) {
            if (atomicUnitEndRecord.getAtomicOperationMetadata().containsKey(ORecordOperationMetadata.RID_METADATA_KEY)) {
              final ORecordOperationMetadata recordOperationMetadata = (ORecordOperationMetadata) atomicUnitEndRecord
                  .getAtomicOperationMetadata().get(ORecordOperationMetadata.RID_METADATA_KEY);

              final Set<ORID> rids = recordOperationMetadata.getValue();
              for (final ORID rid : rids) {
                result.add((ORecordId) rid);
              }
            }
          }

          OLogManager.instance().info(this, "Found %d records changed in last %d operations", result.size(), lastTx.size());

          return result;
        } finally {
          writeAheadLog.removeCutTillLimit(freezeLSN);
        }

      } catch (final IOException e) {
        throw OException.wrapException(new OStorageException("Error on reading last changed records"), e);
      } finally {
        stateLock.releaseReadLock();
      }
    } catch (final RuntimeException e) {
      throw logAndPrepareForRethrow(e);
    } catch (final Error e) {
      throw logAndPrepareForRethrow(e);
    } catch (final Throwable t) {
      throw logAndPrepareForRethrow(t);
    }
  }
public Set<ORecordId> recordsChangedRecently(final int maxEntries) {
    final SortedSet<ORecordId> result = new TreeSet<>();

    try {
      if (!OGlobalConfiguration.STORAGE_TRACK_CHANGED_RECORDS_IN_WAL.getValueAsBoolean()) {
        throw new IllegalStateException(
            "Cannot find records which were changed starting from provided LSN because tracking of rids of changed records in WAL is switched off, "
                + "to switch it on please set property " + OGlobalConfiguration.STORAGE_TRACK_CHANGED_RECORDS_IN_WAL.getKey()
                + " to the true value, please note that only records"
                + " which are stored after this property was set will be retrieved");
      }

      stateLock.acquireReadLock();
      try {
        if (writeAheadLog == null) {
          OLogManager.instance().warn(this, "No WAL found for database '%s'", name);
          return null;
        }

        OLogSequenceNumber startLsn = writeAheadLog.begin();
        if (startLsn == null) {
          OLogManager.instance().warn(this, "The WAL is empty for database '%s'", name);
          return result;
        }

        final OLogSequenceNumber freezeLSN = startLsn;
        writeAheadLog.addCutTillLimit(freezeLSN);
        try {
          //reread because log may be already truncated
          startLsn = writeAheadLog.begin();
          if (startLsn == null) {
            OLogManager.instance().warn(this, "The WAL is empty for database '%s'", name);
            return result;
          }

          final OLogSequenceNumber endLsn = writeAheadLog.end();
          if (endLsn == null) {
            OLogManager.instance().warn(this, "The WAL is empty for database '%s'", name);
            return result;
          }

          List<OWriteableWALRecord> walRecords = writeAheadLog.read(startLsn, 1_000);
          if (walRecords.isEmpty()) {
            OLogManager.instance()
                .info(this, "Cannot find requested LSN=%s for database sync operation (record in WAL is absent)", startLsn);
            return null;
          }

          // KEEP LAST MAX-ENTRIES TRANSACTIONS' LSN
          final List<OAtomicUnitEndRecord> lastTx = new ArrayList<>(1024);
          readLoop:
          while (!walRecords.isEmpty()) {
            for (final OWriteableWALRecord walRecord : walRecords) {
              final OLogSequenceNumber recordLSN = walRecord.getLsn();
              if (endLsn.compareTo(recordLSN) >= 0) {
                if (walRecord instanceof OAtomicUnitEndRecord) {
                  if (lastTx.size() >= maxEntries) {
                    lastTx.remove(0);
                  }

                  lastTx.add((OAtomicUnitEndRecord) walRecord);
                }
              } else {
                break readLoop;
              }
            }

            walRecords = writeAheadLog.next(walRecords.get(walRecords.size() - 1).getLsn(), 1_000);
          }

          // COLLECT ALL THE MODIFIED RECORDS
          for (final OAtomicUnitEndRecord atomicUnitEndRecord : lastTx) {
            if (atomicUnitEndRecord.getAtomicOperationMetadata().containsKey(ORecordOperationMetadata.RID_METADATA_KEY)) {
              final ORecordOperationMetadata recordOperationMetadata = (ORecordOperationMetadata) atomicUnitEndRecord
                  .getAtomicOperationMetadata().get(ORecordOperationMetadata.RID_METADATA_KEY);

              final Set<ORID> rids = recordOperationMetadata.getValue();
              for (final ORID rid : rids) {
                result.add((ORecordId) rid);
              }
            }
          }

          OLogManager.instance().info(this, "Found %d records changed in last %d operations", result.size(), lastTx.size());

          return result;
        } finally {
          writeAheadLog.removeCutTillLimit(freezeLSN);
        }

      } catch (final IOException e) {
        throw OException.wrapException(new OStorageException("Error on reading last changed records"), e);
      } finally {
        stateLock.releaseReadLock();
      }
    } catch (final RuntimeException e) {
      throw logAndPrepareForRethrow(e);
    } catch (final Error e) {
      throw logAndPrepareForRethrow(e);
    } catch (final Throwable t) {
      throw logAndPrepareForRethrow(t);
    }
  }
public Set < ORecordId > recordsChangedRecently ( final int maxEntries ) { final SortedSet < ORecordId > result = new TreeSet <> ( ) ; try { if ( ! OGlobalConfiguration . STORAGE_TRACK_CHANGED_RECORDS_IN_WAL . getValueAsBoolean ( ) ) { throw new IllegalStateException ( "Cannot find records which were changed starting from provided LSN because tracking of rids of changed records in WAL is switched off, " + "to switch it on please set property " + OGlobalConfiguration . STORAGE_TRACK_CHANGED_RECORDS_IN_WAL . getKey ( ) + " to the true value, please note that only records" + " which are stored after this property was set will be retrieved" ) ; } stateLock . acquireReadLock ( ) ; try { if ( writeAheadLog == null ) { OLogManager . instance ( ) . warn ( this , "No WAL found for database '%s'" , name ) ; return null ; } OLogSequenceNumber startLsn = writeAheadLog . begin ( ) ; if ( startLsn == null ) { OLogManager . instance ( ) . warn ( this , "The WAL is empty for database '%s'" , name ) ; return result ; } final OLogSequenceNumber freezeLSN = startLsn ; writeAheadLog . addCutTillLimit ( freezeLSN ) ; try { //reread because log may be already truncated startLsn = writeAheadLog . begin ( ) ; if ( startLsn == null ) { OLogManager . instance ( ) . warn ( this , "The WAL is empty for database '%s'" , name ) ; return result ; } final OLogSequenceNumber endLsn = writeAheadLog . end ( ) ; if ( endLsn == null ) { OLogManager . instance ( ) . warn ( this , "The WAL is empty for database '%s'" , name ) ; return result ; } List < OWriteableWALRecord > walRecords = writeAheadLog . read ( startLsn , 1_000 ) ; if ( walRecords . isEmpty ( ) ) { OLogManager . instance ( ) . info ( this , "Cannot find requested LSN=%s for database sync operation (record in WAL is absent)" , startLsn ) ; return null ; } // KEEP LAST MAX-ENTRIES TRANSACTIONS' LSN final List < OAtomicUnitEndRecord > lastTx = new ArrayList <> ( 1024 ) ; readLoop : while ( ! walRecords . isEmpty ( ) ) { for ( final OWriteableWALRecord walRecord : walRecords ) { final OLogSequenceNumber recordLSN = walRecord . getLsn ( ) ; if ( endLsn . compareTo ( recordLSN ) >= 0 ) { if ( walRecord instanceof OAtomicUnitEndRecord ) { if ( lastTx . size ( ) >= maxEntries ) { lastTx . remove ( 0 ) ; } lastTx . add ( ( OAtomicUnitEndRecord ) walRecord ) ; } } else { break readLoop ; } } walRecords = writeAheadLog . next ( walRecords . get ( walRecords . size ( ) - 1 ) . getLsn ( ) , 1_000 ) ; } // COLLECT ALL THE MODIFIED RECORDS for ( final OAtomicUnitEndRecord atomicUnitEndRecord : lastTx ) { if ( atomicUnitEndRecord . getAtomicOperationMetadata ( ) . containsKey ( ORecordOperationMetadata . RID_METADATA_KEY ) ) { final ORecordOperationMetadata recordOperationMetadata = ( ORecordOperationMetadata ) atomicUnitEndRecord . getAtomicOperationMetadata ( ) . get ( ORecordOperationMetadata . RID_METADATA_KEY ) ; final Set < ORID > rids = recordOperationMetadata . getValue ( ) ; for ( final ORID rid : rids ) { result . add ( ( ORecordId ) rid ) ; } } } OLogManager . instance ( ) . info ( this , "Found %d records changed in last %d operations" , result . size ( ) , lastTx . size ( ) ) ; return result ; } finally { writeAheadLog . removeCutTillLimit ( freezeLSN ) ; } } catch ( final IOException e ) { throw OException . wrapException ( new OStorageException ( "Error on reading last changed records" ) , e ) ; } finally { stateLock . releaseReadLock ( ) ; } } catch ( final RuntimeException e ) { throw logAndPrepareForRethrow ( e ) ; } catch ( final Error e ) { throw logAndPrepareForRethrow ( e ) ; } catch ( final Throwable t ) { throw logAndPrepareForRethrow ( t ) ; } }
This method finds all the records changed in the last X transactions.

@param maxEntries Maximum number of entries to check back from last log.

@return A set of record ids of the changed records

@see OGlobalConfiguration#STORAGE_TRACK_CHANGED_RECORDS_IN_WAL
This method finds all the records changed in the last X transactions .