Transaction Management

Transaction Management#

Important

This notebook is in the process of being migrated to Vast Data Platform Field Docs. It will probably not run yet.

See also

The Vast DB SDK API Documentation is available here.

VAST-DB is ACID compliant. All operations in VAST-DB are transactions, thus the boundaries of these transactions can be moved at will to cover very complex activities. The nature of how data is managed in the metastore makes transaction and transaction roll-back very low-latency. These mechanics are covered in the “Element Store” section.

Install sdk and connect to Vast DB#

Install vastdb library.

!pip install --quiet vastdb
# Change these variables to reflect your environment, E.g. 
#
# ENDPOINT = 'http://your_vast_endpoint:12345'
# DATABASE_NAME = 'your_db'
# ACCESS_KEY = 'your_access_key'
# SECRET_KEY = 'your_secret_key'

Connect to Vast DB

import vastdb

session = vastdb.connect(
    endpoint=ENDPOINT,
    access=ACCESS_KEY,
    secret=SECRET_KEY)

Transactions#

DATABASE_SCHEMA = 'this_should_never_get_created'

with session.transaction() as tx:

    bucket = tx.bucket(DATABASE_NAME)
    bucket.create_schema(DATABASE_SCHEMA, fail_if_exists=False)

    raise Exception("Forcing a failure inside the transaction - transaction should rollback")
    
rolling back txid=000030000000003a due to:
Traceback (most recent call last):
  File "/tmp/ipykernel_1103/47924204.py", line 8, in <module>
    raise Exception("Forcing a failure inside the transaction - transaction should rollback")
Exception: Forcing a failure inside the transaction - transaction should rollback
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[79], line 8
      5 bucket = tx.bucket(DATABASE_NAME)
      6 bucket.create_schema(DATABASE_SCHEMA, fail_if_exists=False)
----> 8 raise Exception("Forcing a failure inside the transaction - transaction should rollback")

Exception: Forcing a failure inside the transaction - transaction should rollback

In the exception above, you should see rolling back txid=... indicating that the transaction was rolled back.

Now let’s print out the schemas to verify that it wasn’t created:

with session.transaction() as tx:

    bucket = tx.bucket(DATABASE_NAME)
    schemas = bucket.schemas()
    print(schemas)