Transaction Log

By default, HarperDB maintains a log of all transactions that occur on every table. Log messages can be used for diagnostics and auditing purposes. The transaction logs are maintained via a HarperDB system table. Transaction log records can be accessed via the read_transaction_log operation. To free up space, transaction logs can be cleared using the delete_transaction_logs_before operation.

 

If a table is dropped, the transaction logs will be dropped as well.

read_transaction_log Operation Parameters

The read_transaction_log is flexible, enabling users to query with many different parameters. All operations search on a single table. Filter options include timestamps, usernames, and table hash values. Additional examples found in the HarperDB API documentation.

Transaction Log Metadata

Each transaction log record may contain the following attributes:

  • operation: The core operation executed on the table.
  • timestamp: The time the operation was executed in Unix Epoch in microseconds format.
  • hash_values: An array of the hash_value(s) of the records affected by the transaction.
  • records: An array of a copy of the newly created/changed records that are stored in the table after the transaction has executed. This attribute will not be included for delete operation records.
  • original_records: An array of a copy of the records before the transaction was executed. This attribute will not be included for insert operation records.

Example Transaction Log Messages

Insert Records

{
  "operation": "insert",
  "user_name": "HDB_ADMIN",
  "timestamp": 1607035556801.436,
  "hash_values": [
    1,
    2
  ],
  "records": [
    {
      "id": 1,
      "name": "Harper",
      "breed": "Mutt",
      "age": 5,
      "__updatedtime__": 1607035556801,
      "__createdtime__": 1607035556801
    },
    {
      "id": 2,
      "name": "Penny",
      "breed": "Mutt",
      "age": 5,
      "__updatedtime__": 1607035556801,
      "__createdtime__": 1607035556801
    }
  ]
}

Update Records

{
  "operation": "update",
  "user_name": "HDB_ADMIN",
  "timestamp": 1607035559122.277,
  "hash_values": [
    1,
    2
  ],
  "records": [
    {
      "id": 1,
      "breed": "Muttzilla",
      "age": 6,
      "__updatedtime__": 1607035559122
    },
    {
      "id": 2,
      "age": 7,
      "__updatedtime__": 1607035559121
    }
  ],
  "original_records": [
    {
      "__createdtime__": 1607035556801,
      "__updatedtime__": 1607035556801,
      "age": 5,
      "breed": "Mutt",
      "id": 2,
      "name": "Penny"
    },
    {
      "__createdtime__": 1607035556801,
      "__updatedtime__": 1607035556801,
      "age": 5,
      "breed": "Mutt",
      "id": 1,
      "name": "Harper"
    }
  ]
}

Delete Records

{
  "operation": "delete",
  "user_name": "HDB_ADMIN",
  "timestamp": 1607035560774.546,
  "hash_values": [
    2
  ],
  "original_records": [
    {
      "__createdtime__": 1607035556801,
      "__updatedtime__": 1607035559121,
      "age": 7,
      "breed": "Mutt",
      "id": 2,
      "name": "Penny"
    }
  ]
}