Skip to content

askids/Akka.Persistence.DB2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Akka.Persistence.DB2

Akka's persistance Journal and snapshot store backed by DB2 database.

This is a clone of the SQL Server Implementation, modified for DB2. Same package can be used for both DB2 z/OS as well as LUW. But the scripts used to create the database objects will slightly vary for LUW variant.

WARNING: Akka.Persistence.DB2 plugin is still in alpha and it's mechanics described bellow may be still subject to change.

Configuration

Both journal and snapshot store share the same configuration keys (however they resides in separate scopes, so they are definied distinctly for either journal or snapshot store):

Remember that connection string must be provided separately to Journal and Snapshot Store.

Unlike other persistent stores, its assumed that table/index creation will be done outside this package. DDL has been provided.

Keep the column names same. But you are free to change table/schema name.

akka.persistence{
	journal {
		DB2 {
			# qualified type name of the DB2 persistence journal actor
			class = "Akka.Persistence.DB2.Journal.DB2Journal, Akka.Persistence.DB2"

			# dispatcher used to drive journal actor
			plugin-dispatcher = "akka.actor.default-dispatcher"

			# connection string used for database access
			connection-string = ""

			# default SQL commands timeout
			connection-timeout = 30s

			# DB2 schema name to table corresponding with persistent journal
			schema-name = ABC

			# DB2 table corresponding with persistent journal
			table-name = EventJournal

			# should corresponding journal table be initialized automatically
			auto-initialize = off

			# timestamp provider used for generation of journal entries timestamps
			timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"

			# metadata table
			metadata-table-name = Metadata
		}
	}

	snapshot-store {
		DB2 {

			# qualified type name of the DB2 persistence journal actor
			class = "Akka.Persistence.DB2.Snapshot.DB2SnapshotStore, Akka.Persistence.DB2"

			# dispatcher used to drive journal actor
			plugin-dispatcher = ""akka.actor.default-dispatcher""

			# connection string used for database access
			connection-string = ""

			# default SQL commands timeout
			connection-timeout = 30s

			# DB2 schema name to table corresponding with persistent journal
			schema-name = ABC

			# DB2 table corresponding with persistent journal
			table-name = SnapshotStore

			# should corresponding journal table be initialized automatically
			auto-initialize = off
		}
	}
}

Table Schema

DB2 persistence plugin will NOT define a default table schema used for journal, snapshot store and metadata table. It needs to be created manually using below query. You will need to create 3 tablespace, 3 table, 3 Primary key, 4 index. You can customize the definition later on to suit your requirements for throughput (like using APPEND, caching etc).

Consult your DBA for selecting the right buffer pool.

--DB2 ON Z/OS

CREATE                     
 TABLESPACE {your_journal_tablespace_name}       
    IN {your_database_name}            
    USING STOGROUP SMSSGDEF
    PRIQTY 720             
    SECQTY -1              
    ERASE NO               
    FREEPAGE 0             
    PCTFREE 10             
    GBPCACHE CHANGED       
    COMPRESS YES           
    TRACKMOD NO            
    LOGGED                 
    DSSIZE 64 G            
    SEGSIZE 64             
    MAXPARTITIONS 1        
    BUFFERPOOL BPXX         
    LOCKSIZE ANY           
    LOCKMAX SYSTEM         
    CLOSE YES              
    CCSID UNICODE           
    MAXROWS 255            
;                          

CREATE TABLE {your_schema_name}.{your_journal_table_name} (
  Ordering BIGINT NOT NULL
  GENERATED BY DEFAULT          
    AS IDENTITY                   
    ( START WITH 1                
      INCREMENT BY 1              
      MINVALUE 1                  
      MAXVALUE 9223372036854775807
      NO CYCLE                    
      NO CACHE                    
      ORDER                    
    ),                             
  PersistenceID VARCHAR(255) NOT NULL,
  SequenceNr BIGINT NOT NULL,
  Timestamp BIGINT NOT NULL,
  IsDeleted BIT NOT NULL,
  Manifest VARCHAR(500) NOT NULL,
  Payload VARBINARY(32704) NOT NULL,
  Tags VARCHAR(100) NULL
  ,                           
   CONSTRAINT PK_{your_journal_table_name}  
   PRIMARY KEY                
   (Ordering)                          
)
  IN {your_database_name}.{your_tablespace_name}
  CCSID UNICODE
  NOT VOLATILE        
  APPEND NO           
;

CREATE UNIQUE                
   INDEX {your_schema_name}.IX_{your_journal_table_name}_1      
  ON {your_schema_name}.{your_journal_table_name}      
   (                         
    Ordering ASC         
   )                         
    USING STOGROUP SMSSGDEF  
    PRIQTY 720             
    SECQTY -1                
    ERASE NO                 
    FREEPAGE 0               
    PCTFREE 10               
    GBPCACHE CHANGED         
    CLUSTER                  
    BUFFERPOOL BPXX           
    CLOSE YES                
    COPY NO                  
    PIECESIZE 2 G            
    COMPRESS NO              
;  

CREATE UNIQUE                
   INDEX {your_schema_name}.IX_{your_journal_table_name}_2    
  ON {your_schema_name}.{your_journal_table_name}      
   (                         
    PersistenceID ASC, SequenceNr ASC
   )                         
    USING STOGROUP SMSSGDEF  
    PRIQTY 720             
    SECQTY -1                
    ERASE NO                 
    FREEPAGE 0               
    PCTFREE 10               
    GBPCACHE CHANGED         
    NOT CLUSTER                  
    BUFFERPOOL BPXX           
    CLOSE YES                
    COPY NO                  
    PIECESIZE 2 G            
    COMPRESS NO              
; 

CREATE                     
 TABLESPACE {your_snapshot_tablespace_name}       
    IN {your_database_name}            
    USING STOGROUP SMSSGDEF
    PRIQTY 720             
    SECQTY -1              
    ERASE NO               
    FREEPAGE 0             
    PCTFREE 10             
    GBPCACHE CHANGED       
    COMPRESS YES           
    TRACKMOD NO            
    LOGGED                 
    DSSIZE 64 G            
    SEGSIZE 64             
    MAXPARTITIONS 1        
    BUFFERPOOL BPXX         
    LOCKSIZE ANY           
    LOCKMAX SYSTEM         
    CLOSE YES              
    CCSID UNICODE           
    MAXROWS 255            
;

CREATE TABLE {your_schema_name}.{your_snapshot_table_name} (
  PersistenceID VARCHAR(255) NOT NULL,
  SequenceNr BIGINT NOT NULL,
  Timestamp DATETIME2 NOT NULL,
  Manifest VARCHAR(500) NOT NULL,
  Snapshot VARBINARY(32704) NOT NULL
  ,                           
   CONSTRAINT PK_{your_journal_table_name}  
   PRIMARY KEY                
   (PersistenceID, SequenceNr)          
  )
  IN {your_database_name}.{your_snapshot_tablespace_name}
  CCSID UNICODE
  NOT VOLATILE        
  APPEND NO   
;

CREATE UNIQUE                
   INDEX {your_schema_name}.IX_{your_snapshot_table_name}_1
  ON {your_schema_name}.{your_snapshot_table_name}      
   (                         
    PersistenceID ASC, SequenceNr ASC
   )                         
    USING STOGROUP SMSSGDEF  
    PRIQTY 720             
    SECQTY -1                
    ERASE NO                 
    FREEPAGE 0               
    PCTFREE 10               
    GBPCACHE CHANGED         
    CLUSTER                  
    BUFFERPOOL BPXX           
    CLOSE YES                
    COPY NO                  
    PIECESIZE 2 G            
    COMPRESS NO              
; 

CREATE                     
 TABLESPACE {your_metadata_tablespace_name}       
    IN {your_database_name}            
    USING STOGROUP SMSSGDEF
    PRIQTY 720             
    SECQTY -1              
    ERASE NO               
    FREEPAGE 0             
    PCTFREE 10             
    GBPCACHE CHANGED       
    COMPRESS YES           
    TRACKMOD NO            
    LOGGED                 
    DSSIZE 64 G            
    SEGSIZE 64             
    MAXPARTITIONS 1        
    BUFFERPOOL BPXX         
    LOCKSIZE ANY           
    LOCKMAX SYSTEM         
    CLOSE YES              
    CCSID UNICODE           
    MAXROWS 255            
;

CREATE TABLE {your_schema_name}.{your_metadata_table_name} (
  PersistenceID VARCHAR(255) NOT NULL,
  SequenceNr BIGINT NOT NULL
  ,                           
   CONSTRAINT PK_{your_metadata_table_name}  
   PRIMARY KEY                
   (PersistenceID, SequenceNr)          
  )
  IN {your_database_name}.{your_metadata_tablespace_name}
  CCSID UNICODE
  NOT VOLATILE        
  APPEND NO ;

CREATE UNIQUE                
   INDEX {your_schema_name}.IX_{your_metadata_table_name}_1
  ON {your_schema_name}.{your_metadata_table_name}      
   (                         
    PersistenceID ASC, SequenceNr ASC
   )                         
    USING STOGROUP SMSSGDEF  
    PRIQTY 720             
    SECQTY -1                
    ERASE NO                 
    FREEPAGE 0               
    PCTFREE 10               
    GBPCACHE CHANGED         
    CLUSTER                  
    BUFFERPOOL BPXX           
    CLOSE YES                
    COPY NO                  
    PIECESIZE 2 G            
    COMPRESS NO              
; 

Underneath Akka.Persistence.DB2 uses a raw ADO.NET commands. You may choose not to use a dedicated built in ones, but to create your own being better fit for your use case. To do so, you have to create your own versions of IJournalQueryBuilder and IJournalQueryMapper (for custom journals) or ISnapshotQueryBuilder and ISnapshotQueryMapper (for custom snapshot store) and then attach inside journal, just like in the example below:

class MyCustomDB2SJournal: Akka.Persistence.DB2.Journal.DB2Journal
{
    public MyCustomDB2Journal() : base()
    {
        QueryBuilder = new MyCustomJournalQueryBuilder();
        QueryMapper = new MyCustomJournalQueryMapper();
    }
}

Tests

The DB2 tests are packaged and run as part of the default "All" build task.

In order to run the tests, you must do the following things:

  1. Download and install IBM DS Driver v10.5 FP7 from: http://www-01.ibm.com/support/docview.wss?uid=swg24041453 (Higher version will also work.
  2. Create the table and indexes using above DDL. Unlike other persistant store, its assumed that table creation is outside the scope of this package.
  3. The default connection string uses the following credentials: "Database=DSXX;User Id=XXXXXXXX;Password=YYYYYYYYY;CurrentSchema=SCHXXX;"
  4. No need to provide the hostname, port on the connection string. Set the value against your database alias on DS Driver Config file (db2dsdriver.cfg).
  5. A custom app.config file can be used and needs to be placed in the same folder as the dll

About

WIP - Akka's persistance Implementation using DB2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages