Quick Start for HVR - Azure Data Lake Storage Gen2
Last updated on Jul 18, 2022
Contents |
---|
This quick start guide helps you to get started with HVR for replicating data into Azure Data Lake Storage (DLS) Gen2.
To proceed with this replication you must have a basic understanding of HVR's architecture and terminologies like Hub, Location, Channel, Location Groups, Actions.
The example here demonstrates how to replicate tables from one local SQL Server database (source location) to Azure DLS Gen2 (target location) residing in the Azure cloud. In real-life scenarios, the source location(s) and the target location(s) typically reside on different machines, and the HVR hub can reside on a separate machine or on the source or target machine. However, in this demonstration, for simplicity, we have the source and hub database on the same machine, and the target on Azure cloud.
For Linux (x64) and Windows (x64), prior to HVR 5.7.0/8 and 5.7.5/4, it is required to install the Hadoop client on the machine from which HVR will access Azure DLS Gen2. For more information, see section Hadoop Client in Requirements for Azure Data Lake Storage Gen2.
Before proceeding with this demonstration, ensure that the requirements for using HVR with Azure DLS Gen2 are met.
For information about access privileges and advanced configuration required for performing replication using SQL Server and Azure DLS Gen2, see:
Create Demo Databases and Tables
The initial step of this demonstration is to create:
- a database in the source location
- tables in the source database (and insert values into these tables)
- an Azure DLS Gen2 storage account and a storage container in the target location
Source Location
Skip this section if you already have a database with tables which you plan to use for this replication.
For this demonstration, in the source location, create a database (e.g. sourcedb) with two tables (e.g. dm01_product and dm01_order), and insert values into these tables.
Target Location
For this demonstration, create the following in the target location (on Azure portal):
- Azure DLS Gen2 storage account (e.g. adlsstorageaccount).
- Azure storage container (e.g. adlscontainer).
- If the authentication type to be used is OAuth, then perform App Registration (in Azure Active Directory) to get the location connection parameters - OAuth2 Endpoint, Client ID, Client Secret.
For information about creating a storage account, container, see Azure Documentation.
Create Hub Database
HVR supports the creation of a hub database on certain databases (location classes) only. For the list of supported location classes, see section Hub Database in Capabilities.
For this demonstration, the hub database (e.g. hvrhub) is created in SQL Server.
Create the hub database using the SQL Server Management Studio. Alternatively, use the following SQL statement:
It is recommended to create a new database schema (e.g. hvrhubschema) for the HVR hub. If an existing database is to be used for HVR Hub, then the HVR's catalog tables can be separated by creating a new database schema and associating it with HVR's user as follows:
create schema hvrhubschema
alter user hvrhub with default_schema=hvrhubschema
Grants/Access Privileges
This section describes the grants/access privileges required for the source and hub databases.
Configure the privileges for the source database (sourcedb).
Configure the privileges for the hub database (hvrhub).
grant create table to hvrhub
grant create procedure to hvrhubgrant select, insert, delete, update on schema::hubschema to hvrhub
grant control on schema::hvrhubschema to hvrhub
Download and Install HVR
Install HVR on a hub machine. For details on installing HVR, see the respective operating system sections:
The HVR distribution requires a license key in order for the software to operate. Please see the HVR licensing page for more details on how to install the HVR license.
After the installation, you can control HVR using the HVR graphical user interface (HVR GUI).
- If the hub machine is Windows, then HVR GUI can be executed directly on the hub machine.
- To control HVR remotely from your PC, connect to the hub machine using Windows Remote Desktop Connection and launch HVR GUI on the hub machine.
- If the hub machine is Linux, then HVR GUI can be executed directly on the hub machine. However, an application like X Server or VNC viewer must be installed to run HVR GUI directly on Linux.
- To control HVR remotely from your PC, install HVR on the PC (with Windows or macOS) and configure the HVR Remote Listener on the hub machine.
- If the hub machine is Unix, then HVR GUI should typically be run remotely from a PC to control HVR installed on the hub machine. To do this, install HVR on the PC (with Windows or macOS) and configure the HVR Remote Listener on the hub machine.
The HVR Remote Listener allows you to connect HVR GUI available on your PC to the remote HVR hub machine. For more information about connecting to remote HVR installation, see Configuring Remote Installation of HVR on Unix or Linux and Configuring Remote Installation of HVR on Windows.
Launch HVR GUI
- On Windows and macOS, double-click the HVR shortcut icon available on the desktop or execute command hvrgui in the CLI.
On Linux, double-click the hvrgui file available in the HVR_extracted_path/bin directory or execute command hvrgui in the CLI.
Linux requires applications like X server or VNC viewer to execute HVR GUI.
On Unix, HVR GUI is not supported. So, HVR GUI should be run on a remote PC (with Windows, Linux, or macOS) to control HVR installed on the Unix machine.
Register Hub
When HVR GUI is launched for the first time, the Register Hub dialog is displayed automatically. The Register Hub dialog can also be accessed from the main menu File ▶ Register Hub.
Skip steps 1 to 4, if HVR GUI is executed directly on the hub machine or if HVR hub is connected to a remote SQL Server database without using the SQL Server protocol. For more information about connecting HVR hub with remote SQL Server database, see section Connecting HVR Hub to a Remote SQL Server Database in Requirements for SQL Server.
Click Connect to HVR on remote machine.
To connect HVR GUI on a PC to a remote HVR hub machine, the HVR Remote Listener must be configured and running on the HVR hub machine.
- Enter the name or IP-address of the hub machine in the Node field (e.g. myserver).
- Enter the port number (defined in the HVR Remote Listener of the hub machine) in the Port field (e.g. 4343).
- Enter the Login (e.g. myserveradmin) and Password for the hub machine. By default, this is the operating system login credentials of the hub machine.
- Select SQL Server in the Class pane.
- Specify Database Connection details. For more information about the Database Connection fields, see section Location Connection.
- Enter the HVR hub database name in the Database field. For example, hvrhub.
- Enter the SQL Server user name in the User field. This username is used to connect HVR to the SQL Server database. For example, hvr.
- Enter the password for the SQL Server user in the Password field.
- Click Connect.
Click OK in the prompt dialog asking to create catalog tables in the hub database. HVR displays this prompt when connecting to a hub database for the first time.
Upon successful connection to the hub database, the navigation tree pane displays the hub machine and the hub database. Location Configuration, Channel Definitions, and Scheduler are displayed under the hub database.
Create Locations
This section describes how to create locations in HVR GUI. A location is a storage place (for example, database or file storage) from where HVR captures (source location) or integrates (target location) changes.
- Create a source location (src) connected to the source database (sourcedb):
- In the navigation tree pane, right-click Location Configuration ▶ New Location.
- Enter Location name and Description for the location.
- For this demonstration, it is not required to select Connect to HVR on remote machine because the source database (sourcedb) and the hub are located on the same machine.
- Select SQL Server in Class.
- Specify Database Connection details. For more information about the Database Connection fields, see section Location Connection.
- Enter the source database name in Database. For example, sourcedb.
- Enter the SQL Server user name in User. This username is used for connecting HVR to SQL Server database. For example, hvr.
- Enter the password for the SQL Server user in Password.
- Click Test Connection to verify the connection to the source database.
- Click OK.
- Create a target location (tgt) connected to the target Azure DLS Gen2 storage account (adlsstorageaccount):
- In the navigation tree pane, right-click Location Configuration ▶ New Location.
- Enter Location name and Description for the location.
- Select Azure DLS Gen2 in Class.
- Specify Azure DLS Gen2 connection details. For more information about the Azure DLS Gen2 connection fields, see section Location Connection.
- Select the security type for connection in Secure Connection. For example, Yes(https).
- Enter the Azure DLS Gen2 storage account name in Account. For example, adlsstorageaccount.
- Enter the Azure storage container name in Container. For example, adlscontainer.
- Enter the Azure storage directory name in Directory. For example, to use the root directory, enter /.
- Specify Authentication details:
- Select the type of authentication for connecting HVR to the Azure DLS in Type. For example, Shared Key.
Enter the access key of the storage account in Secret Key.
If the Authentication type selected is OAuth, enter the credentials in OAuth2 Endpoint, Client ID, Client Secret.
- Enter the SQL Server user name in User. This username is used for connecting HVR to SQL Server database. For example, hvr.
- Enter the password for the SQL Server user in Password.
- Click Test Connection to verify the connection to location database.
- Click OK.
Create Channel
- In the navigation tree pane, right-click Channel Definitions ▶ New Channel.
- In the New Channel dialog, enter Channel name and Description for the channel.
- Click OK.
Create Location Groups
This section describes how to create location groups in a channel. The location groups are used for defining actions on the location. Typically, a channel contains two location groups - one for the source location and one for the target location. Each location group can contain multiple locations.
For this demonstration, create one source location group (SRCGRP) and one target location group (TGTGRP).
- In the navigation tree pane, click + next to the channel (hvrdemo).
- Create source location group (SRCGRP):
- Right-click Location Groups ▶ New Group.
- Enter Group Name and Description for the location group.
- Select source location (src) in Group Membership.
- Click OK.
- Create target location group (TGTGRP):
- Right-click Location Groups ▶ New Group.
- Enter Group Name and Description for the location group.
- Select target location (tgt) in Group Membership.
- Click OK.
Select Table(s)
This section describes how to select the tables (dm01_product and dm01_order) from the source location for replication. The Table Explore dialog allows you to select schema(s) and/or table(s) for replication.
- Right-click Tables ▶ Table Explore.
- Select source location (src) from the list.
- Click Connect.
- Select tables from the Table Explore dialog. Use the Shift or Ctrl key to select multiple tables or Ctrl+A to select all tables.
- Click Add to add the selected tables to the channel.
- Click OK in HVR Table Name dialog.
- Click Close in Table Explore dialog.
Define Actions
This section describes how to define actions on the location groups (SRCGRP and TGTGRP). Actions define the behavior of a replication activity.
- Define action Capture to capture changes from all tables in the source location group.
- Right-click source location group SRCGRP ▶ New Action ▶ Capture.
- Click OK.
- Right-click source location group SRCGRP ▶ New Action ▶ Capture.
- Define action Integrate to integrate changes into all tables in the target location group.
- Right-click target location group TGTGRP ▶ New Action ▶ Integrate.
- Select parameter /RenameExpression. This parameter definition is required for segregation and naming of files integrated into target location.
Enter {hvr_tbl_name}/{hvr_integ_tstamp}.csv.
For each table in the source, a separate folder (with the same name as the table name) is created in the target location, and the files replicated for each table are saved into these folders. The files are named with a timestamp of the moment when the file was integrated into the target location. For other expressions that can be used with this parameter, see Integrate /RenameExpression.
Select parameter /CompareExpression. This parameter definition is required for performing HVR Compare (to verify the replication) against a file location.
Direct file compare does not support Avro, Parquet or JSON file formats.
- Enter {hvr_tbl_name}/*.csv.
- Click OK.
Define action FileFormat to specify the target file format such as XML, CSV, Avro, or JSON. For this demonstration, the target file format is CSV.
- Right-click target location group TGTGRP ▶ New Action ▶ FileFormat.
- Select parameter /Csv to set the target file format as CSV.
- Select parameter /QuoteCharacter to escape any delimiters (e.g. comma) present in a column. If a comma is present in the source location's table, then the QuoteCharacter defined here is added to the beginning and end of the column value in the target location CSV file to indicate that the content enclosed within the QuoteCharacter belongs to one column.
Enter " (double quotes).
This will escape any delimiters (e.g. comma) present in any column. For example, if there is an address column containing value mystreet, mycity, mycountry, then in the target CSV file it is replicated as "mystreet, mycity, mycountry".
- Select parameter /EscapeCharacter to escape the QuoteCharacter defined. If the value in the column for which /QuoteCharacter is defined already contains a character matching the QuoteCharacter, then that character is escaped using the EscapeCharacter.
Enter \ (backslash).
For example, with /QuoteCharacter and /EscapeCharacter defined, if there is an address column containing value mystreet, "mycity", mycountry, then in the target CSV file it is replicated as "mystreet, \"mycity\", mycountry".
Click OK.
- Define action ColumnProperties to define properties for a column being replicated. By default, for file-based target locations, HVR does not replicate the delete operation performed at the source location. To integrate the delete operation, an extra column for TimeKey needs to be added in the target location. For this demonstration, the TimeKey value is generated based on the /IntegrateExpression value {hvr_integ_key} (a 16-byte string value (hex characters) which is unique and continuously incremented for all rows integrated into the target location).
- Right-click target location group TGTGRP ▶ New Action ▶ ColumnProperties.
- Select parameter /Name. This parameter defines the name for the extra column in the target location.
- Enter timekey_col.
- Select parameter /Extra. This parameter defines that this is an extra column in the target location (a column which is not present in the source location).
- Select parameter /IntegrateExpression. This parameter defines the expression to be used for generating the TimeKey value.
- Enter {hvr_integ_key}.
- Select parameter /TimeKey. This parameter defines that this is a TimeKey column.
- Select parameter /Datatype. This parameter defines the data type for the TimeKey column.
- Select varchar2.
- Select parameter /Length. This parameter defines the data type length for the TimeKey column.
- Enter 36.
- Click OK.
Define another action ColumnProperties to define properties for a column being replicated. This action definition adds the source operation type (using hvr_op) information in the target location.
This action definition is required for performing HVR Compare if ColumnProperties /TimeKey column is defined on a target file location.
- Right-click target location group TGTGRP ▶ New Action ▶ ColumnProperties.
- Select parameter /Name. This parameter defines the name for the extra column in the target location.
- Enter src_operation.
- Select parameter /Extra. This parameter defines that this is an extra column in the target location (a column which is not present in the source location).
- Select parameter /IntegrateExpression. This parameter defines the expression to be used for generating the information about source operation type.
- Enter {hvr_op}.
- Select parameter /DataType. This parameter defines the data type for this extra column in the target location.
- Select integer.
- Select integer.
- Click OK.
The Actions pane only displays actions related to the object selected in the navigation tree pane. Click the channel name (hvrdemo) to view all the actions defined for the selected channel.
Optional Actions
The following actions can be defined optionally for this replication:
Group | Table | Action | Annotation |
---|---|---|---|
TGTGRP | * | Integrate /ReorderRows=BATCH_BY_TABLE | Controls the order in which changes are written to files. This action definition is required only if Integrate /RenameExpression does not contain a substitution which depends on the table name. For more information, see Integrate /ReorderRows. |
TGTGRP | * | FileFormat /NullRepresentation | This additional parameter can be defined in FileFormat to represent a NULL column. |
TGTGRP | * | ColumnProperties /Name="src_timestamp", /Extra, /IntegrateExpression={hvr_cap_tstamp}, /DataType=timestamp /Precision=3 | This action definition is optional because HVR does not require this for performing Integrate or Refresh but for further processing, this timestamp may be used to know what has been processed. This action definition can be used to add an extra column in a target file which can be a source commit timestamp ({hvr_cap_tstamp}) or integrate timestamp ({hvr_integ_tstamp}). For other expressions, see ColumnProperties /IntegrateExpression. |
Initialize
This section describes how to initialize the replication. HVR Initialize first checks the channel and creates the replication jobs in the HVR Scheduler.
- Right-click channel hvr_demo ▶ HVR Initialize.
- Select Create or Replace Objects in the HVR Initialize dialog.
- Click Initialize.
- Click OK.
- Click Close in the HVR Initialize dialog.
Click the Scheduler node in the navigation tree pane to view the capture and integrate jobs in the Jobs pane.
For more information about initiating replication in HVR, see section Replication Overview.
Start Scheduler
This section describes how to start the HVR Scheduler. The HVR Scheduler is a process which runs jobs defined in the catalog table HVR_JOB. This catalog table can be found in the hub database. On Unix or Linux, the HVR Scheduler runs as a daemon. On Windows, the HVR Scheduler runs as a system service.
- In the navigation tree pane, right-click Scheduler ▶ Start.
- On Windows, the following steps are required to create the HVR Scheduler system service.
- Click Create... in the prompt asking to create the service hvrscheduler_hvrhub.
- Select Local System Account ('SYSTEM') in the Create Windows Service dialog.
- Click Create.
- Click Create... in the prompt asking to create the service hvrscheduler_hvrhub.
Start Capture Job
This section describes how to start the job for capturing changes from the source location (src). By starting the Capture job in HVR Scheduler, HVR begins capturing all changes since the moment HVR Initialize was executed. This 'capture begin moment' can be modified using option Capture Rewind available in the Advanced Options tab of the HVR Initialize dialog.
- In the navigation tree pane, click Scheduler.
- Start the capture job. In the Jobs pane, right-click capture job hvrdemo-cap-src ▶ Start.
Click Yes in the Start dialog.
On starting the capture job (hvrdemo-cap-src) successfully, the status of the job changes from SUSPEND to RUNNING.
Refresh
This section describes how to perform initial load into the target database. HVR Refresh copies all existing data from the source location (src) to the target location (tgt) and optionally creates new tables and keys in the target location.
- In the navigation tree pane, right-click channel hvrdemo ▶ HVR Refresh.
- Select the table(s) that needs to be copied from the source location to the target location.
- Click Refresh.
- Click Yes to begin HVR Refresh.
When the refresh is completed, the Refresh Result dialog displays the total number of rows replicated from the selected tables. - Click Close in the Refresh Result dialog and then in the HVR Refresh dialog.
Start Integrate Job
This section describes how to start the job to integrate changes into the target location (tgt).
- In the navigation tree pane, click Scheduler.
- Start the integrate job. In the Jobs pane, right-click integrate job hvrdemo-integ-tgt ▶ Start.
Click Yes in the Start dialog.
On starting the integrate job (hvr_demo-integ-tgt) successfully, the status of the job changes from SUSPEND to RUNNING.
Verify Replication
This section describes two methods for verifying the HVR's replication activity.
Viewing Log File
HVR creates separate log files for the hub, channel (hvrdemo), and for each replication jobs (hvrdemo-cap-src and hvrdemo-integ-tgt). These log files contain the details of the changes captured and integrated.
Replication can be verified by inspecting the channel log file.
To view the replication activity log:
- In the navigation tree pane, click + next to the Scheduler.
- Right-click hvr_demo ▶ View Log to view the log of both Capture and Integrate jobs.
The logs for both Capture and Integrate jobs is displayed in the logs pane (Log of channel hvrdemo) at the bottom of the screen.
The directory path for the HVR log files is displayed in the log tab.
Right-clicking on a particular job and selecting View Log displays logs related to that job alone.
Insert, update, or delete value(s) in the source location database. For example:
insert into dm01_product
values (101, 91, 'Pencil')The output log is updated and indicates that the change is captured from the source location and integrated into the target location:
- This replication can also be verified by manually checking the ADLS storage directory (dm01_product).
Using HVR Compare
HVR Compare allows you to verify the replication activity by comparing the data in source and target locations. For file locations without Hive External Tables, HVR supports only Direct File Compare.
To run HVR Compare against a file location, ensure that the parameter Integrate /ComparePattern is defined.
To compare the source and target locations:
- Suspend the integrate job (hvrdemo-integ-tgt),
- In the navigation tree pane, click Scheduler.
- In the Jobs pane, right-click integrate job hvrdemo-integ-tgt ▶ Suspend.
- Click Yes in the Suspend dialog.
Insert, update, or delete value(s) in the source location database. For example:
insert into dm01_product
values (101, 91, 'Pencil')- Execute HVR Compare:
- In the navigation tree pane, right-click channel hvrdemo ▶ HVR Compare.
- Select the source location (src) on the left side and the target location (tgt) on the right side.
- Select Generate Compare Event in the Scheduling tab
- Click Compare.
- On completion, the compare result is displayed in the web browser. If the State column displays DONE/DIFFERENT, it indicates the data in the source and target locations are not identical.
- Start Integrate Job (hvrdemo-integ-tgt), the changes made in source location (in step 2) will be integrated to the target location now.
- Execute HVR Compare again (step 3). In the compare result screen, if the State column displays DONE/IDENTICAL, it indicates the changes are replicated successfully.