Class FileWrapperJournal

  • All Implemented Interfaces:
    Journal, org.apache.activemq.artemis.core.server.ActiveMQComponent

    public final class FileWrapperJournal
    extends java.lang.Object
    Journal used at a replicating backup server during the synchronization of data with the 'live' server. It just wraps a single JournalFile. Its main purpose is to store the data as a Journal would, but without verifying records.
    • Field Detail

      • currentFile

        protected volatile JournalFile currentFile
      • fileSize

        protected final int fileSize
      • removeExtraFilesOnLoad

        protected boolean removeExtraFilesOnLoad
    • Constructor Detail

      • FileWrapperJournal

        public FileWrapperJournal​(Journal journal)
                           throws java.lang.Exception
        Parameters:
        journal -
        Throws:
        java.lang.Exception
    • Method Detail

      • replaceableRecord

        public void replaceableRecord​(byte recordType)
      • start

        public void start()
                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • stop

        public void stop()
                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • isStarted

        public boolean isStarted()
      • appendAddRecord

        public void appendAddRecord​(long id,
                                    byte recordType,
                                    org.apache.activemq.artemis.core.persistence.Persister persister,
                                    java.lang.Object record,
                                    boolean sync,
                                    IOCompletion callback)
                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • appendAddEvent

        public void appendAddEvent​(long id,
                                   byte recordType,
                                   org.apache.activemq.artemis.core.persistence.Persister persister,
                                   java.lang.Object record,
                                   boolean sync,
                                   IOCompletion callback)
                            throws java.lang.Exception
        Description copied from interface: Journal
        An event is data recorded on the journal, but it won't have any weight or deletes. It's always ready to be removed. It is useful on recovery data while in use with backup history journal.
        Throws:
        java.lang.Exception
      • flush

        public void flush()
                   throws java.lang.Exception
        Description copied from interface: Journal
        It will make sure there are no more pending operations on the Executors.
        Throws:
        java.lang.Exception
      • getMaxRecordSize

        public long getMaxRecordSize()
        The max size record that can be stored in the journal
        Returns:
      • appendDeleteRecord

        public void appendDeleteRecord​(long id,
                                       boolean sync,
                                       IOCompletion callback)
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • tryAppendDeleteRecord

        public void tryAppendDeleteRecord​(long id,
                                          boolean sync,
                                          JournalUpdateCallback updateCallback,
                                          IOCompletion callback)
                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • appendDeleteRecordTransactional

        public void appendDeleteRecordTransactional​(long txID,
                                                    long id,
                                                    EncodingSupport record)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • appendAddRecordTransactional

        public void appendAddRecordTransactional​(long txID,
                                                 long id,
                                                 byte recordType,
                                                 org.apache.activemq.artemis.core.persistence.Persister persister,
                                                 java.lang.Object record)
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • appendUpdateRecord

        public void appendUpdateRecord​(long id,
                                       byte recordType,
                                       org.apache.activemq.artemis.core.persistence.Persister persister,
                                       java.lang.Object record,
                                       boolean sync,
                                       IOCompletion callback)
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • tryAppendUpdateRecord

        public void tryAppendUpdateRecord​(long id,
                                          byte recordType,
                                          org.apache.activemq.artemis.core.persistence.Persister persister,
                                          java.lang.Object record,
                                          boolean sync,
                                          boolean replaceableUpdate,
                                          JournalUpdateCallback updateCallback,
                                          IOCompletion callback)
                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • appendUpdateRecordTransactional

        public void appendUpdateRecordTransactional​(long txID,
                                                    long id,
                                                    byte recordType,
                                                    org.apache.activemq.artemis.core.persistence.Persister persister,
                                                    java.lang.Object record)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • appendCommitRecord

        public void appendCommitRecord​(long txID,
                                       boolean sync,
                                       IOCompletion callback,
                                       boolean lineUpContext)
                                throws java.lang.Exception
        lineUpContext - if appendCommitRecord should call a storeLineUp. This is because the caller may have already taken into account
        Throws:
        java.lang.Exception
      • appendPrepareRecord

        public void appendPrepareRecord​(long txID,
                                        EncodingSupport transactionData,
                                        boolean sync,
                                        IOCompletion callback)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • appendRollbackRecord

        public void appendRollbackRecord​(long txID,
                                         boolean sync,
                                         IOCompletion callback)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • loadInternalOnly

        public JournalLoadInformation loadInternalOnly()
                                                throws java.lang.Exception
        Description copied from interface: Journal
        Load internal data structures and not expose any data. This is only useful if you're using the journal but not interested on the current data. Useful in situations where the journal is being replicated, copied... etc.
        Throws:
        java.lang.Exception
      • lineUpContext

        public void lineUpContext​(IOCompletion callback)
      • getAlignment

        public int getAlignment()
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getNumberOfRecords

        public int getNumberOfRecords()
      • getUserVersion

        public int getUserVersion()
      • loadSyncOnly

        public JournalLoadInformation loadSyncOnly​(Journal.JournalState state)
                                            throws java.lang.Exception
        Description copied from interface: Journal
        Load internal data structures, and remain waiting for synchronization to complete.
        Parameters:
        state - the current state of the journal, this parameter ensures consistency.
        Throws:
        java.lang.Exception
      • createFilesForBackupSync

        public java.util.Map<java.lang.Long,​JournalFile> createFilesForBackupSync​(long[] fileIds)
                                                                                 throws java.lang.Exception
        Description copied from interface: Journal
        Reserves journal file IDs, creates the necessary files for synchronization, and places references to these (reserved for sync) files in the map.

        During the synchronization between a live server and backup, we reserve in the backup the journal file IDs used in the live server. This call also makes sure the files are created empty without any kind of headers added.

        Parameters:
        fileIds - IDs to reserve for synchronization
        Returns:
        map to be filled with id and journal file pairs for synchronization.
        Throws:
        java.lang.Exception
      • synchronizationLock

        public void synchronizationLock()
        Description copied from interface: Journal
        Write lock the Journal and write lock the compacting process. Necessary only during replication for backup synchronization.
      • synchronizationUnlock

        public void synchronizationUnlock()
        Description copied from interface: Journal
        Unlock the Journal and the compacting process.
        See Also:
        Journal.synchronizationLock()
      • forceMoveNextFile

        public void forceMoveNextFile()
        Description copied from interface: Journal
        Force the usage of a new JournalFile.
      • scheduleCompactAndBlock

        public void scheduleCompactAndBlock​(int timeout)
                                     throws java.lang.Exception
        Description copied from interface: Journal
        This method will start compact using the compactorExecutor and block up to timeout seconds
        Parameters:
        timeout - the timeout in seconds or block forever if <= 0
        Throws:
        java.lang.Exception
      • replicationSyncPreserveOldFiles

        public void replicationSyncPreserveOldFiles()
        Description copied from interface: Journal
        Stops any operation that may delete or modify old (stale) data.

        Meant to be used during synchronization of data between a live server and its replicating (remote) backup. Old files must not be compacted or deleted during synchronization.

      • replicationSyncFinished

        public void replicationSyncFinished()
        Description copied from interface: Journal
        Restarts file reclaim and compacting on the journal.

        Meant to be used to revert the effect of Journal.replicationSyncPreserveOldFiles(). it should only be called once the synchronization of the backup and live servers is completed.

      • appendAddRecord

        public void appendAddRecord​(long id,
                                    byte recordType,
                                    byte[] record,
                                    boolean sync)
                             throws java.lang.Exception
        Specified by:
        appendAddRecord in interface Journal
        Throws:
        java.lang.Exception
      • appendAddRecord

        public void appendAddRecord​(long id,
                                    byte recordType,
                                    org.apache.activemq.artemis.core.persistence.Persister persister,
                                    java.lang.Object record,
                                    boolean sync)
                             throws java.lang.Exception
        Specified by:
        appendAddRecord in interface Journal
        Throws:
        java.lang.Exception
      • appendCommitRecord

        public void appendCommitRecord​(long txID,
                                       boolean sync)
                                throws java.lang.Exception
        Specified by:
        appendCommitRecord in interface Journal
        Throws:
        java.lang.Exception
      • appendCommitRecord

        public void appendCommitRecord​(long txID,
                                       boolean sync,
                                       IOCompletion callback)
                                throws java.lang.Exception
        Specified by:
        appendCommitRecord in interface Journal
        Throws:
        java.lang.Exception
      • appendUpdateRecord

        public void appendUpdateRecord​(long id,
                                       byte recordType,
                                       byte[] record,
                                       boolean sync)
                                throws java.lang.Exception
        Specified by:
        appendUpdateRecord in interface Journal
        Throws:
        java.lang.Exception
      • tryAppendUpdateRecord

        public void tryAppendUpdateRecord​(long id,
                                          byte recordType,
                                          byte[] record,
                                          JournalUpdateCallback updateCallback,
                                          boolean sync,
                                          boolean replaceableRecord)
                                   throws java.lang.Exception
        Specified by:
        tryAppendUpdateRecord in interface Journal
        Throws:
        java.lang.Exception
      • appendUpdateRecordTransactional

        public void appendUpdateRecordTransactional​(long txID,
                                                    long id,
                                                    byte recordType,
                                                    byte[] record)
                                             throws java.lang.Exception
        Specified by:
        appendUpdateRecordTransactional in interface Journal
        Throws:
        java.lang.Exception
      • appendAddRecordTransactional

        public void appendAddRecordTransactional​(long txID,
                                                 long id,
                                                 byte recordType,
                                                 byte[] record)
                                          throws java.lang.Exception
        Specified by:
        appendAddRecordTransactional in interface Journal
        Throws:
        java.lang.Exception
      • appendDeleteRecordTransactional

        public void appendDeleteRecordTransactional​(long txID,
                                                    long id)
                                             throws java.lang.Exception
        Specified by:
        appendDeleteRecordTransactional in interface Journal
        Throws:
        java.lang.Exception
      • appendPrepareRecord

        public void appendPrepareRecord​(long txID,
                                        byte[] transactionData,
                                        boolean sync)
                                 throws java.lang.Exception
        Specified by:
        appendPrepareRecord in interface Journal
        Throws:
        java.lang.Exception
      • appendPrepareRecord

        public void appendPrepareRecord​(long txID,
                                        EncodingSupport transactionData,
                                        boolean sync)
                                 throws java.lang.Exception
        Description copied from interface: Journal

        If the system crashed after a prepare was called, it should store information that is required to bring the transaction back to a state it could be committed.

        transactionData allows you to store any other supporting user-data related to the transaction

        Specified by:
        appendPrepareRecord in interface Journal
        transactionData - - extra user data for the prepare
        Throws:
        java.lang.Exception
      • appendDeleteRecordTransactional

        public void appendDeleteRecordTransactional​(long txID,
                                                    long id,
                                                    byte[] record)
                                             throws java.lang.Exception
        Specified by:
        appendDeleteRecordTransactional in interface Journal
        Throws:
        java.lang.Exception
      • appendUpdateRecord

        public void appendUpdateRecord​(long id,
                                       byte recordType,
                                       org.apache.activemq.artemis.core.persistence.Persister persister,
                                       java.lang.Object record,
                                       boolean sync)
                                throws java.lang.Exception
        Specified by:
        appendUpdateRecord in interface Journal
        Throws:
        java.lang.Exception
      • tryAppendUpdateRecord

        public void tryAppendUpdateRecord​(long id,
                                          byte recordType,
                                          org.apache.activemq.artemis.core.persistence.Persister persister,
                                          java.lang.Object record,
                                          JournalUpdateCallback updateCallback,
                                          boolean sync,
                                          boolean replaceableUpdate)
                                   throws java.lang.Exception
        Specified by:
        tryAppendUpdateRecord in interface Journal
        Throws:
        java.lang.Exception
      • appendRollbackRecord

        public void appendRollbackRecord​(long txID,
                                         boolean sync)
                                  throws java.lang.Exception
        Specified by:
        appendRollbackRecord in interface Journal
        Throws:
        java.lang.Exception
      • appendDeleteRecord

        public void appendDeleteRecord​(long id,
                                       boolean sync)
                                throws java.lang.Exception
        Specified by:
        appendDeleteRecord in interface Journal
        Throws:
        java.lang.Exception
      • getSyncCallback

        protected SyncIOCompletion getSyncCallback​(boolean sync)