Skip to content

epoch migration command#768

Open
elliVM wants to merge 39 commits intoteragrep:mainfrom
elliVM:epoch-migration-step
Open

epoch migration command#768
elliVM wants to merge 39 commits intoteragrep:mainfrom
elliVM:epoch-migration-step

Conversation

@elliVM
Copy link
Copy Markdown
Contributor

@elliVM elliVM commented Dec 15, 2025

Description

Implement support for a command to update missing epoch values of S3 object metadata in the archive SQL. Works by running the archive datasource in an epoch migration mode, where epoch value is fetched to the returned schemas _time column.

  • Updates the pth_03 version to 9.4.0 with teragrep exec migration epoch command support
  • Adds jooq library for dynamic SQL building
  • Update the SQL logtime metadata of the S3 objects using epoch migration mode from the archiver
  • Epoch migraiton mode of PTH_06 provides a calculated epoch value of the first even of the S3 in the _time column. In the _raw column there is a JSON format metadata about the event, this can be used to see how the event was parsed and what was the source of the _time column epoch.

Testing

Included unit and dpl tests

General

  • I have checked that my test files and functions have meaningful names.
  • I have checked that each test tests only a single behavior.
  • I have done happy tests.
  • I have tested only my own code.
  • I have tested at least all public methods.

Assertions

  • I have checked that my tests use assertions and not runtime overhead.
  • I have checked that my tests end in assertions.
  • I have checked that there is no comparison statements in assertions.
  • I have checked that assertions are in tests and not in helper functions.
  • I have checked that assertions for iterables are outside of for loops and both sides of the iteration blocks.
  • I have checked that assertions are not tested inside consumers.

Testing Data

  • I have tested algorithms and anything else with the possibility of unbound growth.
  • I have checked that all testing data is local and fully replaceable or reproducible or both.
  • I have checked that all test files are standalone.
  • I have checked that all test-specific fake objects and classes are in the test directory.
  • I have checked that my tests do not contain anything related to customers, infrastructure or users.
  • I have checked that my tests do not contain non-generic information.
  • I have checked that my tests do not do external requests and are not privately or publicly routable.

Statements

  • I have checked that my tests do not use throws for exceptions.
  • I have checked that my tests do not use try-catch statements.
  • I have checked that my tests do not use if-else statements.

Java

  • I have checked that my tests for Java uses JUnit library.
  • I have checked that my tests for Java uses JUnit utilities for parameters.

Other

  • I have only tested public behavior and not private implementation details.
  • I have checked that my tests are not (partially) commented out.
  • I have checked that hand-crafted variables in assertions are used accordingly.
  • I have tested Object Equality.
  • I have checked that I do not have any manual tests or I have a valid reason for them and I have explained it in the PR description.

Code Quality

  • I have checked that my code follows metrics set in Procedure: Class Metrics.
  • I have checked that my code follows metrics set in Procedure: Method Metrics.
  • I have checked that my code follows metrics set in Procedure: Object Quality.
  • I have checked that my code does not have any NULL values.
  • I have checked my code does not contain FIXME or TODO comments.

@elliVM elliVM self-assigned this Dec 15, 2025
@elliVM elliVM linked an issue Dec 15, 2025 that may be closed by this pull request
@elliVM elliVM changed the title epoch migration step epoch migration command Dec 15, 2025
@elliVM elliVM force-pushed the epoch-migration-step branch from 0434986 to 205dfd3 Compare January 28, 2026 09:18
@elliVM elliVM force-pushed the epoch-migration-step branch 2 times, most recently from 8b6df08 to ccbb108 Compare February 5, 2026 09:19
final String partitionString = row.getString(row.fieldIndex("partition"));
final long id = Long.parseLong(partitionString);

if (!metadata.isSyslog() && LOGGER.isInfoEnabled()) {
Copy link
Copy Markdown
Contributor Author

@elliVM elliVM Feb 5, 2026

Choose a reason for hiding this comment

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

Currently non syslog rows are updated to SQL since the epoch migration mode provides the path extracted value in the _time column. This is logged with metadata from the row.

Is this acceptable or should we do more here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kortemik what do you think is this fine as it is?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Main point being that should these cases be added to the corrupted logfiles in the archive schema

Copy link
Copy Markdown
Member

@kortemik kortemik Mar 17, 2026

Choose a reason for hiding this comment

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

It must be extracted properly from json in the _raw field. Also the object format should be updated in the same go

@elliVM elliVM marked this pull request as ready for review February 5, 2026 10:07
@elliVM elliVM requested a review from Tiihott February 5, 2026 10:38
Copy link
Copy Markdown

@Tiihott Tiihott left a comment

Choose a reason for hiding this comment

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

Object equality tests should be added for some new classes.
Please rebase.

Comment thread src/test/java/com/teragrep/pth_10/EpochMigrationStepTest.java
@elliVM elliVM force-pushed the epoch-migration-step branch from bb9d02d to 5b57d2d Compare February 10, 2026 10:13
@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Feb 10, 2026

rebased

@elliVM elliVM requested a review from Tiihott February 11, 2026 10:51
Copy link
Copy Markdown

@Tiihott Tiihott left a comment

Choose a reason for hiding this comment

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

Tests fail when run via maven.

@elliVM elliVM force-pushed the epoch-migration-step branch from 17823f6 to 9b20d0b Compare February 12, 2026 11:14
@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Feb 12, 2026

rebased

@elliVM elliVM marked this pull request as draft February 18, 2026 11:02
@elliVM elliVM force-pushed the epoch-migration-step branch from dbc66fb to 481d8b9 Compare February 24, 2026 13:03
@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Feb 24, 2026

rebased and switched to use new connection pool objects

@elliVM elliVM marked this pull request as ready for review February 24, 2026 13:33
@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Feb 25, 2026

tests keep failing in actions with connection pool initialization errors

@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Feb 26, 2026

working build now

@elliVM elliVM requested a review from Tiihott February 26, 2026 08:38
Tiihott
Tiihott previously approved these changes Feb 27, 2026
Copy link
Copy Markdown

@Tiihott Tiihott left a comment

Choose a reason for hiding this comment

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

All tests pass and changes look fine, LGTM.

@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Feb 27, 2026

Doing testing in QA

@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Feb 27, 2026

Issues in QA

  • Caused by: java.sql.SQLException: No suitable driver executor class path does not have JDBC driver available. FIX: added hikariConfig.setDriverClassName("org.mariadb.jdbc.Driver") to maybe have it load in the executor. if not the executors need to be provided with the driver some other way I think.
  • archive.url/bloomdb url uses bloomdb database FIX: changed to use archive db credentials

Tiihott
Tiihott previously approved these changes Mar 2, 2026
Copy link
Copy Markdown

@Tiihott Tiihott left a comment

Choose a reason for hiding this comment

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

Tests pass and new changes look ok. A new test run in QA should be done to check if the credential and JDBC driver fixes resolve the issues found in QA.

@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Mar 2, 2026

I think the JDBC driver must be added to the spark executor jars

elliVM added 24 commits April 9, 2026 14:18
…qualified names in the before each SQL setup
…gleton before each in EpochMigrationStepTest
…y to try both to parse the json to a result EventMetadata
@elliVM elliVM force-pushed the epoch-migration-step branch from 3891cc9 to eaa68f9 Compare April 9, 2026 11:18
@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Apr 9, 2026

rebased


@Override
public EventMetadata get() {
final List<EventMetadata> validEvents = formats
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

functional programming API is not preferred. please change to object oriented one.

*/
package com.teragrep.pth_10.steps.teragrep.migrate;

public interface EventMetadata {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

preferred name is ArchiveObjectMetadata

import java.util.function.Supplier;
import java.util.stream.Collectors;

final class EventMetadataFactory implements Supplier<EventMetadata> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be just a decorator to EventMetadata which takes in at ctor the list of possible formats and the EventMetadata. when changing to such design the decorator can directly implement the EventMetadata and return the format via format() by running the code which we have here in get()


import java.util.function.Supplier;

public interface CandidateFormat extends Supplier<EventMetadata> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this interace is unnecessary, please return Stub / illegal argument exception from format() if not matching

import java.io.StringReader;
import java.util.Objects;

public final class ParsedJson {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is a json parsER object. instead it should be implementing EventMetadata directly


private long resolveFromDatabase(final String objectFormat) {
try {
// plain SQL since jooq can't insert into a generic table
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i am unsure what this comment is about? table is defined on L104 here?

import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

final class ResolvedObjectFormats {
Copy link
Copy Markdown
Member

@kortemik kortemik Apr 10, 2026

Choose a reason for hiding this comment

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

this is unnecessary and error-prone. One should do this as a transaction via inline or as a stored procedure so that database takes care of the proper id selection at the insert.

START TRANSACTION;

INSERT INTO format (name)
VALUES ('rfc5424-syslog')
ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id);

UPDATE foo (format_id)
VALUES (LAST_INSERT_ID()) WHERE id=123;

COMMIT;

this uses an upsert pattern.


import jakarta.json.JsonObject;

final class SyslogEvent implements EventMetadata {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this SyslogArchiveObject? Event is a naming mistake to avoid.

@elliVM
Copy link
Copy Markdown
Contributor Author

elliVM commented Apr 27, 2026

changing to a temp table solution and using a stored procedure to update from temp table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement a spark job to update missing logfile epoch metadataa

3 participants