Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
753618b
Util classes for data loader
inv-jishnu Dec 4, 2024
8d39d02
Fix spotbug issue
inv-jishnu Dec 4, 2024
bf94c49
Removed error message and added core error
inv-jishnu Dec 6, 2024
47be388
Applied spotless
inv-jishnu Dec 6, 2024
913eb1c
Fixed unit test failures
inv-jishnu Dec 6, 2024
1f204b8
Merge branch 'master' into feat/data-loader/utils
ypeckstadt Dec 11, 2024
6cfa83a
Basic data import enum and exception
inv-jishnu Dec 11, 2024
d381b2b
Removed exception class for now
inv-jishnu Dec 11, 2024
67f2474
Added DECIMAL_FORMAT
inv-jishnu Dec 12, 2024
14e3593
Path util class updated
inv-jishnu Dec 12, 2024
a096d51
Feedback changes
inv-jishnu Dec 13, 2024
dbf1940
Merge branch 'master' into feat/data-loader/utils
ypeckstadt Dec 13, 2024
cd8add9
Merge branch 'master' into feat/data-loader/utils
ypeckstadt Dec 16, 2024
52890c8
Changes
inv-jishnu Dec 16, 2024
5114639
Merge branch 'master' into feat/data-loader/import-data-1
inv-jishnu Dec 17, 2024
4f9cd75
Merge branch 'feat/data-loader/utils' into feat/data-loader/scaladb-dao
inv-jishnu Dec 17, 2024
1997eb8
Added ScalarDB Dao
inv-jishnu Dec 17, 2024
91e6310
Merge branch 'master' into feat/data-loader/scaladb-dao
inv-jishnu Dec 17, 2024
8a7338b
Remove unnecessary files
inv-jishnu Dec 17, 2024
2b52eeb
Initial commit [skip ci]
inv-jishnu Dec 17, 2024
e206073
Changes
inv-jishnu Dec 17, 2024
26d3144
Changes
inv-jishnu Dec 18, 2024
b86487d
spotbugs exclude
inv-jishnu Dec 18, 2024
818a2b4
spotbugs exclude -2
inv-jishnu Dec 18, 2024
90c4105
Added a file [skip ci]
inv-jishnu Dec 18, 2024
3d5d3e0
Added unit test files [skip ci]
inv-jishnu Dec 18, 2024
6495202
Spotbug fixes
inv-jishnu Dec 19, 2024
90abd9e
Removed use of List.of to fix CI error
inv-jishnu Dec 19, 2024
ba2b3dd
Merged changes from master after resolving conflict
inv-jishnu Dec 19, 2024
b1b811b
Merge branch 'master' into feat/data-loader/metadata-service
inv-jishnu Dec 19, 2024
30db988
Applied spotless
inv-jishnu Dec 19, 2024
e9bb004
Added export options validator
inv-jishnu Dec 19, 2024
03324e1
Minor change in test
inv-jishnu Dec 19, 2024
d6aaf85
Applied spotless on CoreError
inv-jishnu Dec 19, 2024
4439dea
Make constructor private and improve javadocs
ypeckstadt Dec 19, 2024
ccb1ace
Improve javadocs
ypeckstadt Dec 20, 2024
a374f1a
Add private constructor to TableMetadataUtil
ypeckstadt Dec 20, 2024
a65c9b5
Apply spotless fix
ypeckstadt Dec 20, 2024
b3279ba
Fix the validation for partition and clustering keys
ypeckstadt Dec 23, 2024
78a8170
Fix spotless format
ypeckstadt Dec 23, 2024
acedabe
Partial feedback changes
inv-jishnu Dec 24, 2024
bf31a01
Data chunk and task result enums and dtos
inv-jishnu Dec 24, 2024
57cd330
Spotless applied
inv-jishnu Dec 24, 2024
7a39564
Changes
inv-jishnu Dec 26, 2024
a95a858
Resolved conflicts and merged latest changes from main
inv-jishnu Dec 26, 2024
093cb1d
Merge branch 'feat/data-loader/scaladb-dao' into feat/data-loader/imp…
inv-jishnu Dec 31, 2024
bfebd95
Merge branch 'feat/data-loader/metadata-service' into feat/data-loade…
inv-jishnu Dec 31, 2024
fd1c186
Control file files
inv-jishnu Dec 31, 2024
e2cc6ac
Added task files and dtos
inv-jishnu Jan 2, 2025
8c75b79
Fix unit test failure
inv-jishnu Jan 2, 2025
98618aa
Fix spot bugs failure
inv-jishnu Jan 2, 2025
c05286d
Merge branch 'feat/data-loader/scaladb-dao' into feat/data-loader/exp…
inv-jishnu Jan 2, 2025
0d3f79e
Export tasks added
inv-jishnu Jan 2, 2025
2365460
Merge branch 'feat/data-loader/metadata-service' into feat/data-loade…
inv-jishnu Jan 2, 2025
95022a9
Initial commit [skip ci]
inv-jishnu Jan 2, 2025
be4583c
Added transaction batch dtos
inv-jishnu Jan 3, 2025
89fea78
Added changes
inv-jishnu Jan 6, 2025
29a8c25
Fix spot less issue
inv-jishnu Jan 6, 2025
45adc95
Merge branch 'master' into feat/data-loader/export-tasks
inv-jishnu Jan 6, 2025
5568a7b
Merge branch 'feat/data-loader/import-utils-dtos' into feat/data-load…
inv-jishnu Jan 6, 2025
67dcb06
Merge branch 'master' into feat/data-loader/scaladb-dao
ypeckstadt Jan 7, 2025
2b58dcb
Initial commit
inv-jishnu Jan 8, 2025
cebb543
Merge branch 'master' into feat/data-loader/control-file
ypeckstadt Jan 8, 2025
8ecb39c
Changes -1
inv-jishnu Jan 9, 2025
c7ba6c8
Description added
inv-jishnu Jan 10, 2025
a566ef2
Code updated to support java 8
inv-jishnu Jan 13, 2025
f6c54ec
Updated test code to remove warning
inv-jishnu Jan 13, 2025
b92758c
Merged latest changes from main after resolving conflicts
inv-jishnu Jan 13, 2025
ee252d2
Added import manager
inv-jishnu Jan 14, 2025
90c4830
Changes added
inv-jishnu Jan 16, 2025
39c43de
Removed scalardb manager file
inv-jishnu Jan 16, 2025
3fe30a3
Merge branch 'master' into feat/data-loader/scaladb-dao
inv-jishnu Jan 20, 2025
4df4acd
Removed wildcard import
inv-jishnu Jan 20, 2025
53cd523
Merge branch 'master' into feat/data-loader/scaladb-dao
inv-jishnu Jan 23, 2025
f4f253e
Changes
inv-jishnu Jan 28, 2025
6d43bdc
Merge branch 'master' into feat/data-loader/scaladb-dao
inv-jishnu Jan 28, 2025
9c4ae23
Resolved conflicts and merge latest changes from master
inv-jishnu Jan 28, 2025
c9d01cb
Added default case in switch to resolve sportbugs warning
inv-jishnu Jan 28, 2025
50be8fd
Merge branch 'master' into feat/data-loader/import-process
inv-jishnu Jan 28, 2025
9224c7b
Merge branch 'master' into feat/data-loader/import-task
inv-jishnu Jan 28, 2025
5e61fd1
Merge branch 'master' into feat/data-loader/control-file
inv-jishnu Jan 28, 2025
f024670
Merge branch 'feat/data-loader/scaladb-dao' into feat/data-loader/con…
inv-jishnu Jan 29, 2025
d453e6c
Change wildcard imports
inv-jishnu Jan 30, 2025
39ecefe
Merge changes from master after resolving conflicts
inv-jishnu Jan 31, 2025
0984d51
Resolved conflicts and merged latest changes from main
inv-jishnu Feb 3, 2025
aadf3e1
Resolved conflicts and merged latest changes from master
inv-jishnu Feb 3, 2025
6998b68
Changes
inv-jishnu Feb 3, 2025
3c79ab6
Merged changes from master after resolving conflicts
inv-jishnu Feb 3, 2025
3ff03d9
Merge branch 'master' into feat/data-loader/export-tasks
inv-jishnu Feb 4, 2025
f3fb8d8
Merge branch 'master' into feat/data-loader/control-file
inv-jishnu Feb 4, 2025
6dd2ce2
Resolved conflicts and merged changes from branch feat/data-loader/co…
inv-jishnu Feb 4, 2025
1996865
Reverted new line removal
inv-jishnu Feb 4, 2025
8a1e6b9
Merge branch 'feat/data-loader/import-task' into feat/data-loader/imp…
inv-jishnu Feb 4, 2025
3187847
Changes to util function calls
inv-jishnu Feb 4, 2025
da2e241
Merge export tasks branch after resolving conflicts
inv-jishnu Feb 4, 2025
7d7ec91
Revert "Merge export tasks branch after resolving conflicts"
inv-jishnu Feb 4, 2025
31094b1
Resolved conflicts and merged latest changes from main
inv-jishnu Feb 7, 2025
aebcef6
Removing unwanted changes [skip ci]
inv-jishnu Feb 7, 2025
b5134b1
Changes
inv-jishnu Feb 10, 2025
285f51d
Java doc minor change [skip ci]
inv-jishnu Feb 10, 2025
01ce7d3
Merged changes from feat/data-loader/import-task after resolving conf…
inv-jishnu Feb 10, 2025
9cadea4
Constant file added
inv-jishnu Feb 10, 2025
40fde36
Changes from master merged after resolving conflicts
inv-jishnu Feb 13, 2025
0dd2956
Error messages and adding java docs
inv-jishnu Feb 13, 2025
9d3ffb1
Resolved conflicts and merged latest changes from master
inv-jishnu Feb 24, 2025
868d9b5
Column util correction
inv-jishnu Feb 26, 2025
e4cd7fe
Minor corrections
inv-jishnu Feb 26, 2025
d0a73a3
Changes
inv-jishnu Mar 4, 2025
bffa85b
gradle change reverted
inv-jishnu Mar 4, 2025
328afe5
Resolved conflicts and merged changes from master
inv-jishnu Mar 4, 2025
adc7e56
Spotless applied
inv-jishnu Mar 4, 2025
5b61876
Fixed unit test
inv-jishnu Mar 4, 2025
b9842be
Reverted try-catch changes
inv-jishnu Mar 5, 2025
16ae46d
Optimizations
inv-jishnu Mar 10, 2025
6b2536e
Error message changes and further optimizations
inv-jishnu Mar 10, 2025
6aea83c
Improve javadocs for the data loader import process
ypeckstadt Mar 17, 2025
851b691
Changes added
inv-jishnu Mar 25, 2025
c835730
Removed unused test util methods [skip ci]
inv-jishnu Mar 25, 2025
ff87a9a
Merge branch 'master' into feat/data-loader/import-process
inv-jishnu Mar 25, 2025
8f7adc8
Fixed spotbugs test issues
inv-jishnu Mar 25, 2025
3aff018
reader data updated [skip ci]
inv-jishnu Mar 25, 2025
35a758f
Merge branch 'master' into feat/data-loader/import-process
inv-jishnu Mar 25, 2025
24bfa37
Changes
inv-jishnu Apr 1, 2025
05ac8ff
Merge branch 'master' into feat/data-loader/import-process
inv-jishnu Apr 2, 2025
d9f239c
Thread exexcuter changes
inv-jishnu Apr 3, 2025
723bd51
Changed few values to be configurable
inv-jishnu Apr 3, 2025
450aaea
Added new line
inv-jishnu Apr 4, 2025
aeaa08f
reverted config utils and add CLI options
inv-jishnu Apr 6, 2025
44bf503
Updated tests
inv-jishnu Apr 7, 2025
a5c0b91
Removed explict passing of thread size and use it directly
inv-jishnu Apr 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions core/src/main/java/com/scalar/db/common/error/CoreError.java
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,30 @@ public enum CoreError implements ScalarDbError {
""),
DATA_LOADER_FILE_FORMAT_NOT_SUPPORTED(
Category.USER_ERROR, "0178", "The provided file format is not supported : %s", "", ""),
DATA_LOADER_COULD_NOT_FIND_PARTITION_KEY(
Category.USER_ERROR, "0179", "Could not find the partition key", "", ""),
DATA_LOADER_UPSERT_INSERT_MISSING_COLUMNS(
Category.USER_ERROR,
"0180",
"The source record needs to contain all fields if the UPSERT turns into an INSERT",
"",
""),
DATA_LOADER_DATA_ALREADY_EXISTS(Category.USER_ERROR, "0181", "Record already exists", "", ""),
DATA_LOADER_DATA_NOT_FOUND(Category.USER_ERROR, "0182", "Record was not found", "", ""),
DATA_LOADER_COULD_NOT_FIND_CLUSTERING_KEY(
Category.USER_ERROR, "0183", "Could not find the clustering key", "", ""),
DATA_LOADER_TABLE_METADATA_MISSING(
Category.USER_ERROR, "0184", "No table metadata found", "", ""),
DATA_LOADER_MISSING_SOURCE_FIELD(
Category.USER_ERROR,
"0185",
"The data mapping source field '%s' for table '%s' is missing in the json data record",
"",
""),
DATA_LOADER_CSV_DATA_MISMATCH(
Category.USER_ERROR, "0186", "The CSV row: %s does not match header: %s.", "", ""),
DATA_LOADER_JSON_CONTENT_START_ERROR(
Category.USER_ERROR, "0187", "Expected JSON file content to be an array", "", ""),

//
// Errors for the concurrency error category
Expand Down Expand Up @@ -1087,6 +1111,20 @@ public enum CoreError implements ScalarDbError {
"Something went wrong while scanning. Are you sure you are running in the correct transaction mode? Details: %s",
"",
""),
DATA_LOADER_CSV_FILE_READ_FAILED(
Category.INTERNAL_ERROR, "0049", "Failed to read CSV file. Details: %s.", "", ""),
DATA_LOADER_CSV_FILE_HEADER_READ_FAILED(
Category.INTERNAL_ERROR, "0050", "Failed to CSV read header line. Details: %s.", "", ""),
DATA_LOADER_DATA_CHUNK_PROCESS_FAILED(
Category.INTERNAL_ERROR,
"0051",
"Data chunk processing was interrupted. Details: %s",
"",
""),
DATA_LOADER_JSON_FILE_READ_FAILED(
Category.INTERNAL_ERROR, "0052", "Failed to read JSON file. Details: %s.", "", ""),
DATA_LOADER_JSONLINES_FILE_READ_FAILED(
Category.INTERNAL_ERROR, "0053", "Failed to read JSON Lines file. Details: %s.", "", ""),

//
// Errors for the unknown transaction status error category
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.scalar.db.dataloader.core.dataimport;

import com.scalar.db.dataloader.core.dataimport.datachunk.ImportDataChunkStatus;
import com.scalar.db.dataloader.core.dataimport.task.result.ImportTaskResult;
import com.scalar.db.dataloader.core.dataimport.transactionbatch.ImportTransactionBatchResult;
import com.scalar.db.dataloader.core.dataimport.transactionbatch.ImportTransactionBatchStatus;

/**
* Listener interface for monitoring import events during the data loading process. Implementations
* can use this to track progress and handle various stages of the import process.
*/
public interface ImportEventListener {

/**
* Called when processing of a data chunk begins.
*
* @param status the current status of the data chunk being processed
*/
void onDataChunkStarted(ImportDataChunkStatus status);

/**
* Updates or adds new status information for a data chunk.
*
* @param status the updated status information for the data chunk
*/
void addOrUpdateDataChunkStatus(ImportDataChunkStatus status);

/**
* Called when processing of a data chunk is completed.
*
* @param status the final status of the completed data chunk
*/
void onDataChunkCompleted(ImportDataChunkStatus status);

/**
* Called when all data chunks have been processed. This indicates that the entire chunked import
* process is complete.
*/
void onAllDataChunksCompleted();

/**
* Called when processing of a transaction batch begins.
*
* @param batchStatus the initial status of the transaction batch
*/
void onTransactionBatchStarted(ImportTransactionBatchStatus batchStatus);

/**
* Called when processing of a transaction batch is completed.
*
* @param batchResult the result of the completed transaction batch
*/
void onTransactionBatchCompleted(ImportTransactionBatchResult batchResult);

/**
* Called when an import task is completed.
*
* @param taskResult the result of the completed import task
*/
void onTaskComplete(ImportTaskResult taskResult);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package com.scalar.db.dataloader.core.dataimport;

import com.scalar.db.api.DistributedStorage;
import com.scalar.db.api.DistributedTransactionManager;
import com.scalar.db.api.TableMetadata;
import com.scalar.db.dataloader.core.ScalarDBMode;
import com.scalar.db.dataloader.core.dataimport.dao.ScalarDBDao;
import com.scalar.db.dataloader.core.dataimport.datachunk.ImportDataChunkStatus;
import com.scalar.db.dataloader.core.dataimport.processor.ImportProcessor;
import com.scalar.db.dataloader.core.dataimport.processor.ImportProcessorFactory;
import com.scalar.db.dataloader.core.dataimport.processor.ImportProcessorParams;
import com.scalar.db.dataloader.core.dataimport.processor.TableColumnDataTypes;
import com.scalar.db.dataloader.core.dataimport.task.result.ImportTaskResult;
import com.scalar.db.dataloader.core.dataimport.transactionbatch.ImportTransactionBatchResult;
import com.scalar.db.dataloader.core.dataimport.transactionbatch.ImportTransactionBatchStatus;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.AllArgsConstructor;
import lombok.NonNull;

/**
* Manages the data import process and coordinates event handling between the import processor and
* listeners. This class implements {@link ImportEventListener} to receive events from the processor
* and relay them to registered listeners.
*
* <p>The import process involves:
*
* <ul>
* <li>Reading data from an input file
* <li>Processing the data in configurable chunk sizes
* <li>Managing database transactions in batches
* <li>Notifying listeners of various import events
* </ul>
*/
@AllArgsConstructor
public class ImportManager implements ImportEventListener {

@NonNull private final Map<String, TableMetadata> tableMetadata;
@NonNull private final BufferedReader importFileReader;
@NonNull private final ImportOptions importOptions;
private final ImportProcessorFactory importProcessorFactory;
private final List<ImportEventListener> listeners = new ArrayList<>();
private final ScalarDBMode scalarDBMode;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like I missed this in the previous PR review, but we should rename this to ScalarDbMode. We should also rename ScalarDBDao and ScalarDBDaoException accordingly.

Could you please handle this in a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create another PR for the changes mentioned.
Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brfrn169 san,
I have created PR #2582 to address this. I will mark it ready for review once this PR is merged.
Thank you.

private final DistributedStorage distributedStorage;
private final DistributedTransactionManager distributedTransactionManager;
private final ConcurrentHashMap<Integer, ImportDataChunkStatus> importDataChunkStatusMap =
new ConcurrentHashMap<>();

/**
* Starts the import process using the configured parameters.
*
* <p>If the data chunk size in {@link ImportOptions} is set to 0, the entire file will be
* processed as a single chunk. Otherwise, the file will be processed in chunks of the specified
* size.
*
* @return a map of {@link ImportDataChunkStatus} objects containing the status of each processed
* chunk
*/
public ConcurrentHashMap<Integer, ImportDataChunkStatus> startImport() {
ImportProcessorParams params =
ImportProcessorParams.builder()
.scalarDBMode(scalarDBMode)
.importOptions(importOptions)
.tableMetadataByTableName(tableMetadata)
.dao(new ScalarDBDao())
.distributedTransactionManager(distributedTransactionManager)
.distributedStorage(distributedStorage)
.tableColumnDataTypes(getTableColumnDataTypes())
.build();
ImportProcessor processor = importProcessorFactory.createImportProcessor(params);
processor.addListener(this);
// If the data chunk size is 0, then process the entire file in a single data chunk
int dataChunkSize =
importOptions.getDataChunkSize() == 0
? Integer.MAX_VALUE
: importOptions.getDataChunkSize();
return processor.process(
dataChunkSize, importOptions.getTransactionBatchSize(), importFileReader);
}

/**
* Registers a new listener to receive import events.
*
* @param listener the listener to add
* @throws IllegalArgumentException if the listener is null
*/
public void addListener(ImportEventListener listener) {
listeners.add(listener);
}

/**
* Removes a previously registered listener.
*
* @param listener the listener to remove
*/
public void removeListener(ImportEventListener listener) {
listeners.remove(listener);
}

/** {@inheritDoc} Forwards the event to all registered listeners. */
@Override
public void onDataChunkStarted(ImportDataChunkStatus status) {
for (ImportEventListener listener : listeners) {
listener.onDataChunkStarted(status);
}
}

/**
* {@inheritDoc} Updates or adds the status of a data chunk in the status map. This method is
* thread-safe.
*/
@Override
public void addOrUpdateDataChunkStatus(ImportDataChunkStatus status) {
importDataChunkStatusMap.put(status.getDataChunkId(), status);
}

/** {@inheritDoc} Forwards the event to all registered listeners. */
@Override
public void onDataChunkCompleted(ImportDataChunkStatus status) {
for (ImportEventListener listener : listeners) {
listener.onDataChunkCompleted(status);
}
}

/** {@inheritDoc} Forwards the event to all registered listeners. */
@Override
public void onTransactionBatchStarted(ImportTransactionBatchStatus status) {
for (ImportEventListener listener : listeners) {
listener.onTransactionBatchStarted(status);
}
}

/** {@inheritDoc} Forwards the event to all registered listeners. */
@Override
public void onTransactionBatchCompleted(ImportTransactionBatchResult batchResult) {
for (ImportEventListener listener : listeners) {
listener.onTransactionBatchCompleted(batchResult);
}
}

/** {@inheritDoc} Forwards the event to all registered listeners. */
@Override
public void onTaskComplete(ImportTaskResult taskResult) {
for (ImportEventListener listener : listeners) {
listener.onTaskComplete(taskResult);
}
}

/** {@inheritDoc} Forwards the event to all registered listeners. */
@Override
public void onAllDataChunksCompleted() {
for (ImportEventListener listener : listeners) {
listener.onAllDataChunksCompleted();
}
}

/**
* Returns the current map of import data chunk status objects.
*
* @return a map of {@link ImportDataChunkStatus} objects
*/
public ConcurrentHashMap<Integer, ImportDataChunkStatus> getImportDataChunkStatus() {
return importDataChunkStatusMap;
}

/**
* Creates and returns a mapping of table column data types from the table metadata.
*
* @return a {@link TableColumnDataTypes} object containing the column data types for all tables
*/
public TableColumnDataTypes getTableColumnDataTypes() {
TableColumnDataTypes tableColumnDataTypes = new TableColumnDataTypes();
tableMetadata.forEach(
(name, metadata) ->
metadata
.getColumnDataTypes()
.forEach((k, v) -> tableColumnDataTypes.addColumnDataType(name, k, v)));
return tableColumnDataTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ public class ImportOptions {
private final String tableName;
private final int maxThreads;
private final String customHeaderRow;
private final int dataChunkQueueSize;
}
Loading
Loading