CYFILE

CYFILE

CYFILE is a tool which uses Change Data Capture (CDC) method to store the altered data in Comma-Separated Values (CSV) format file.

Overview

It analyzes the redo log file in real time and stores the transaction executed in the database in CSV format file. It can replicate the transaction file which is recorded in an async way and in near real time to database by using the 3rd party tool, or converts it to another format.

Operational Features

Operational Restrictions

The server property DISABLE_DDL_CDC_GIVEUP can disable the DDL statement which causes the replication give up to avoid user created errors. Also, the server property DISABLE_UPDATE_PK_CDC_GIVEUP can disable primary key update.

Others

It stores the file at the following moment.

Requirements

It is required to perform GOLDILOCKS preparations, user registration and privilege settings.

GOLDILOCKS Requirements

The following should be set in GOLDILOCKS before starting CYFILE.

SUPPLEMENTAL LOGGING

SUPPLEMENTAL LOGGING stores an additional information together in the redo log file. The database should be restarted to change the settings of operating database, but restarting is not needed when setting SUPPLEMENTAL LOGGING only in the specific table.

Setting SUPPLEMENTAL LOGGING in Database

Setting SUPPLEMENTAL LOGGING in Specific Table Participating in the Replication

<add table supplemental log statement> ::=
    ALTER TABLE table_name 
        ADD SUPPLEMENTAL LOG DATA ( PRIMARY KEY ) COLUMNS
    ;

ARCHIVE LOG

GOLDILOCKS reuses the redo log files recursively. When GOLDILOCKS reuses the redo log file being processed by CYFILE, then CYFILE does not proceed and is terminated. GOLDILOCKS should be operated in ARCHIVE LOG mode to ensure the continuous replication operation.

Changing Database in Operation to ARCHIVE LOG Mode

gSQL> \startup mount

Startup success

gSQL> alter database archivelog;

Database altered.

Setting ARCHIVE LOG Mode When Creating Database

The path in which ARCHIVE LOG file is stored can be viewed and updated with 'ARCHIVELOG_DIR'.

DATA_STORE_MODE

CYFILE performs the replication by reading the redo log files of GOLDILOCKS. Therefore, GOLDILOCKS should be operated in Transactional Data Store (TDS) mode.

Changing DATA_STORE_MODE

If the value of DATA_STORE_MODE is 1, it indicates Concurrent Data Store (CDS), and if it is 2, it indicates Transactional Data Store (TDS).

Registering User and Setting Privileges

CYFILE retrieves and manipulates the required information during the operation. The user operating CYFILE and the proper privileges for the user are required.

Creating Database User

A specific user should be added to operate CYFILE.

<user definition> ::=
    CREATE USER user_identifier IDENTIFIED BY password
    [ DEFAULT TABLESPACE tablespace_name ]
    [ TEMPORARY TABLESPACE tablespace_name ]
    [ INDEX TABLESPACE {tablespace_name|NULL} ]
    [ <schema clause> ]
    ;

<schema clause> ::=
      WITH SCHEMA [schema_name]
    | WITHOUT SCHEMA

The following is an example of creating the user cyfile_user and the password cyfile_password.

gSQL> CREATE USER cyfile_user IDENTIFIED BY cyfile_password;

Database Privileges

Granting User Access Privilege

The following is an example for granting the access privilege to cyfile_user.

gSQL> GRANT CREATE SESSION ON DATABASE TO cyfile_user;

Configuration

Configuration File

When performing CYFILE, the information and options required for operating are set by using the configuration file.

Configuration file options

Name

Description

DSN

It sets Data Source Name.

GROUP_NAME

It sets the group name.

HOST_IP

It sets the host IP address of which GOLDILOCKS operates.

HOST_PORT

It sets the host port of which GOLDILOCKS operates.

USER_ID

It sets the user name.

USER_PW

It sets the user password.

USER_ENCRYPT_PW

It sets the encrypted password for a user.

CAPTURE_TABLE

It sets the table to be replicated.

PROTOCOL

It sets the connection type which is to be connected to GOLDILOCKS. (DA or TCP)

READ_LOG_BLOCK_COUNT

It sets the amount of data to be read at a time when operating CAPTURE.

TRANS_SORT_AREA_SIZE

It sets the size of the BUFFER to be allocated to CAPTURE.

TRANS_FILE_PATH

It sets the location in which the temporarily generated file is to be stored when operating CAPTURE.

LOG_CAPTURE_INTERVAL_1

It sets the execution cycle of capture. If the value is not changed after executing 10 times with that value, then it is converted to the value of LOG_CAPTURE_INTERVAL_2 and performs capture. (The default value is 0.2 seconds.)

LOG_CAPTURE_INTERVAL_2

It sets the execution cycle of capture. If the value is not changed after executing with the value of LOG_CAPTURE_INTERVAL_1, then it sets the execution cycle of capture. (The default value is 1 second.)

DATA_FILE_PATH

It sets the path to store CSV file. (It should be an absolute path.)

DATA_FILE_PREFIX

It sets the prefix of CSV file name.

DATA_FILE_SIZE

It sets the maximum size of CSV file. (It is an approximate size and it is not always set to the specified value.)

UPDATE_BEFORE_VALUE

It sets whether to store the value before the update in CSV when processing update SQL. (The default value is 0.)

Configuration Options

DSN

• Settings applied to all groups

DSN=GOLDILOCKS

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    DSN=GOLDILOCKS
    ....
    ....
}

GROUP_NAME

GROUP_NAME = testGROUP
{
    ....
    ....
}

HOST_IP

• Settings applied to all groups

HOST_IP = 127.0.0.1

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    HOST_IP = 127.0.0.1
    ....
    ....
}

HOST_PORT

• Settings applied to all groups

HOST_PORT = 22531

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    HOST_PORT = 22531
    ....
    ....
}

USER_ID

It sets the user ID required for the access to GOLDILOCKS.

• Settings applied to all groups

USER_ID = testID

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    USER_ID = testID
    ....
    ....
}

USER_PW

It sets the user password required for the access to GOLDILOCKS.

• Settings applied to all groups

USER_PW = testPW

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    USER_PW = testPW
    ....
    ....
}

USER_ENCRYPT_PW

• Settings applied to all groups

USER_ENCRYPT_PW = 't33KImiqvhqNyfN+uZmFrw=='

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    USER_ENCRYPT_PW = 't33KImiqvhqNyfN+uZmFrw=='
    ....
    ....
}

CAPTURE_TABLE

GROUP_NAME = testGROUP
{
    CAPTURE_TABLE = 
    (
        testSchema1.testTable1,
        testSchema1.testTable2,
        testSchema2.testTable1
    )
}

PROTOCOL

• Settings applied to all groups

PROTOCOL = DA

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    PROTOCOL = DA
    ....
    ....
}

READ_LOG_BLOCK_COUNT

• Settings applied to all groups

READ_LOG_BLOCK_COUNT = 1024

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    READ_LOG_BLOCK_COUNT = 1024
    ....
    ....
}

TRANS_SORT_AREA_SIZE

• Settings applied to all groups

TRANS_SORT_AREA_SIZE = 300

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    TRANS_SORT_AREA_SIZE = 300
    ....
    ....
}

TRANS_FILE_PATH

• Settings applied to all groups

TRANS_FILE_PATH = '/data/TmpTrans'

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    TRANS_FILE_PATH = '/data/TmpTrans'
    ....
    ....
}

LOG_CAPTURE_INTERVAL_1

• Settings applied to all groups

LOG_CAPTURE_INTERVAL_1 = 200

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    LOG_CAPTURE_INTERVAL_1 = 200
    ....
    ....
}

LOG_CAPTURE_INTERVAL_2

• Settings applied to all groups

LOG_CAPTURE_INTERVAL_2 = 1000

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    LOG_CAPTURE_INTERVAL_2 = 1000
    ....
    ....
}

DATA_FILE_PATH

• Settings applied to all groups

DATA_FILE_PATH = '/home/goldilocks/dat'

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    DATA_FILE_PATH = '/home/goldilocks/dat'
    ....
    ....
}

DATA_FILE_PREFIX

• Settings applied to all groups

DATA_FILE_PREFIX = 'SET_PREFIX'

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    DATA_FILE_PREFIX = 'SET_PREFIX'
    ....
    ....
}

DATA_FILE_SIZE

• Settings applied to all groups

DATA_FILE_SIZE = 200

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    DATA_FILE_SIZE = 200
    ....
    ....
}

UPDATE_BEFORE_VALUE

• Settings applied to all groups

UPDATE_BEFORE_VALUE = 1

• Settings applied to a specific group

GROUP_NAME = testGROUP
{
    UPDATE_BEFORE_VALUE = 1
    ....
    ....
}

Operating

CYFILE can be operated in D/A or C/S environment of GOLDILOCKS.
CONFIG file or PROTOCOL configuration of ODBC.INI should be used according to the environments as follows. CONFIG configuration takes precedence over ODBC.INI configuration.
CONFIG, ODBC.INI

Configuration

Description

PROTOCOL=DA

It is used in D/A environment. (Default)

PROTOCOL=TCP

It is used in C/S environment.

The running contents during the operation can be viewed through trace log.

Item

File

Cyfile

$GOLDILOCKS_DATA/trc/cyfile_(groupName).trc

Executing Option

CYFILE should be used with the following options at run-time.

Executing options

Option

Description

Remarks

--start | -s

It starts CYFILE.

-

--stop | -t

It stops CYFILE.

-

--status | -u

It displays the status of CYFILE.

-

--conf | -c

It sets the path of configuration file which is required when executing CYFILE.

It is input in --conf CONFIG_FILE format.

It should be used together with --start.

If it is not explicitly set,

$GOLDILOCKS_DATA/conf/cyfile.conf is used.

--silent | -i

It sets not to output messages.

-

--reset | -r

It resets the information about capture.

It is input in --reset TABLE_NAME or --reset all format.

It should be described within a single quote (') when resetting multiple tables.

--group | -g

It sets a specific group.

It is input in --group GROUP_NAME format.

--help | -h

It outputs the help message.

-

--encrypt | -e

It encrypts the user password with the given key.

-

--key | -k

It sets the encryption key when performing the --encrypt option.

If USER_ENCRYPT_PW is used in the config, it sets the decryption key.

-

--info | -o

It displays the status of currently running table.

It should be used together with --group.

prompt> cyfile --start
prompt> cyfile --stop
prompt> cyfile --start --group TEST_GROUP
prompt> cyfile --stop --group TEST_GROUP
prompt> cyfile --encrypt test --key 1234
Cyfile Encrypted Passwd : '73LsLxss6lk='
prompt> cyfile --start --key 1234
prompt> cyfile --start --reset all
prompt> cyfile --start --reset 'T1, T2'
prompt> cyfile --info --group GROUP1

================================================
 GROUP NAME = GROUP1
================================================
 SCHEMA NAME         : PUBLIC
 TABLE NAME          : TEST_TABLE_02 (ACTIVE (CAPTURE-START-LSN:217368))
 PHYSICAL ID         : 36313948487680
 STATUS              : ONLINE
================================================
 SCHEMA NAME         : PUBLIC
 TABLE NAME          : TEST_TABLE_01 (ACTIVE (CAPTURE-START-LSN:217602))
 PHYSICAL ID         : 36322538422272
 STATUS              : ONLINE
================================================
   TOTAL   COUNT : 2
   GIVE-UP COUNT : 0
   NODE          : TRUST
================================================

Files

CYFILE stores the information about insert/ update/ delete and capture table in CSV format. It uses async method but it is operated in near real-time.
There are two types of file for storage when operating CYFILE, which are the data file and the control file. The data file stores the transaction in CSV format and the control file stores the storage information about the data file. The control file creates and operates the mirror file in preparation for data loss or damage.
CYFILE

File

Name information

Data file

It is stored in CSV format, and the extension is dat.

Control file

The extension is ctl.

The extension of mirror file is ctl_0.

Data File

It records I/D/U information which is performed in transaction unit and in CSV format, the information about the column of the table participating in capture and give up table information. Those files are not automatically deleted unless a user deletes them.

File Name

The location and name of the stored file is determined by DATA_FILE_PREFIX, DATA_FILE_PATH. The extension is .dat and it is created according to the following rules.

When a new file is created because the data file size becomes bigger than DATA_FILE_SIZE, then the value is determined by adding 1 to FILE_SEQUENCE.

DATA_FILE_PATH, DATA_FILE_PREFIX should not be changed after it starts the operation.

INSERT Storage Format

INSERT expression

INSERT expression

Query: INSERT INTO PUBLIC.TEST(C1, C2, C3) VALUES( 1, 2, 'ABC' );
CSV storage: T, I, "PUBLIC", "TEST", "C1", "1", "C2", "2", "C3", "ABC"
Query: INSERT INTO PUBLIC.TEST(C1, C3) VALUES( 1, ABC );
CSV storage: T, I, "PUBLIC", "TEST", "C1", "1", "C2", NULL, "C3", "ABC"

DELETE Storage Format

DELETE expression

DELETE expression

Sample: When there is one primary key
Query: DELETE FROM PUBLIC.TEST WHERE C1=1;
CSV storage: T, D, "PUBLIC", "TEST", 1, "C1", "1"
Sample: When there are two or more primary keys
Query: DELETE FROM PUBLIC.TEST WHERE C1=1 AND C2=2;
CSV storage: T, D, "PUBLIC", "TEST", 2, "C1", "1", "C2", "2"

UPDATE Storage Format

UPDATE expression

UPDATE expression

Sample: C2 value in the record whose primary key is only c1 is changed from 1 to 2. 
Query: UPDATE PUBLIC.TEST SET C2=2 WHERE C1=1;

* When UPDATE_BEFORE_VALUE is not set
CSV storage: T, U, "PUBLIC", "TEST", 1, "C1", "1", "C2", "2"

* When UPDATE_BEFORE_VALUE is set
CSV storage: T, U, "PUBLIC", "TEST", 1, "C1", "1", "C2", "1", "2"
Sample: Change C3 value from 'ABC' to 'BCD', and C4 value from 3 to 4 in the record whose primary keys are C1, C2.
Query: UPDATE PUBLIC.TEST SET C3='BCD', C4=4 WHERE C1=1 AND C2=2;

* When UPDATE_BEFORE_VALUE is not set
CSV storage: T, U, "PUBLIC", "TEST", 2, "C1", "1", "C2", "2", "C3", "BCD", "C4", "4"

* When UPDATE_BEFORE_VALUE is set
CSV storage: T, U, "PUBLIC", "TEST", 2, "C1", "1", "C2", "2", "C3", "ABC", "BCD", "C4", "3", "4"

Transaction Information

Transaction begin expression

Transaction begin expression

Transaction commit expression

Transaction commit expression

Table Information

Table expression

Table expression

COLUMN expression

COLUMN expression

I,T,"PUBLIC","TEST",3,1
I,C,"C1","NUMBER(10,0)",1,0,0
I,C,"C2","VARCHAR(20)",0,0,1
I,C,"C3","VARCHAR(10)",0,0,1
I,T,"PUBLIC","TEST2",2,1
I,C,"C1","NUMBER(10,0)",1,0,0
I,C,"C2","VARCHAR(20)",0,0,1

Meta Information

Version expression

Version expression

Date information expression

Date information expression

Control file information expression

Control file information expression

I,V, 00000000
I,D,"2022-12-24 00:01:00.000000"
I,M,"/home/cyfile/ctrl_file/cyfile.GROUP1.ctl"

Command Information

EOF expression

EOF expression

Control File

typedef struct ctrlFileStr
{
    char           mVersion[8];
    unsigned int   mFileInfoCrc;   //mFileSeq + mFileOffset CRC
    unsigned int   mDummy;         //Not Used.
   
    signed long    mFileSeq;
    signed long    mFileOffset;    //Valid Offset
} ctrlFileStr;