Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CONFIG-398] Reflector: query ctlstore_dml_ledger using shard fields (families, tables) #141

Conversation

zhou-hongyu
Copy link
Contributor

@zhou-hongyu zhou-hongyu commented Feb 15, 2024

  • Add shard info to reflector configs, so that reflector is able to query ctlstore_dml_ledger tables using family_name.
  • Query ctlstore_dml_ledger tables using table_name.
  • If shard info is empty reflector will still fetch everything.
  • If family_name exists but no table_name won't fetch anything(Is it desired?)

Testing done by UTs.

@zhou-hongyu zhou-hongyu force-pushed the hzhou/CONFIG-398-reflector-query-ctlstore-dml-ledger-using-shard-fields-families-tables branch from ac135f8 to fa0f995 Compare February 20, 2024 19:03
erikdw and others added 2 commits February 20, 2024 14:32
## Description

Update the `go-sqlite3` dependency for Ctlstore to get to the latest upstream version from https://github.com/mattn/go-sqlite3.

Notably we depend on a Segment-specific fork that includes a patch which enables preupdate hooks for our code without requiring a build-time flag to be manually put into place by all users of the ctlstore library.

## Details

This depends on segmentio/go-sqlite3#9 to allow the `go get` to succeed.

Once that is merged, we deleted the [segment-v1.14.22](https://github.com/segmentio/go-sqlite3/releases/tag/segment-v1.14.22) tag in that repo and recreated it as [v1.14.22-segment](https://github.com/segmentio/go-sqlite3/releases/tag/v1.14.22-segment).

> [!TIP]
> Despite fixing the `master` of go-sqlite3 to [update module path](https://github.com/segmentio/go-sqlite3/blob/b9c49a6eaf4ca03f2515c9ef9334d20741363b3b/go.mod#L1), I was getting errors doing `go get` after deleting and recreating the `segment-v1.14.22` tag like so:
> ```
> % go get github.com/segmentio/[email protected]
> go: github.com/segmentio/[email protected] (v1.14.23-0.20240208202956-73b5bef61db6) > requires github.com/segmentio/[email protected]: parsing go.mod:
> 	module declares its path as: github.com/mattn/go-sqlite3
> 	        but was required as: github.com/segmentio/go-sqlite3
> ```
>
> @kevinburkesegment explained this was likely due to the Go package cache, so we decided to just delete that previous tag and not try to recreate it. Instead we created a tag with a different name.

Testing completed successfully: 
* [x] ensure CI runs
* [x] verify on other services that include ctlstore client, when those services are updated. https://segment.atlassian.net/browse/IO-1695

> [!NOTE]  
> Replacement for PR #140 which had the wrong version number in its branch name.
@zhou-hongyu zhou-hongyu force-pushed the hzhou/CONFIG-398-reflector-query-ctlstore-dml-ledger-using-shard-fields-families-tables branch from fa0f995 to 519bf36 Compare February 20, 2024 19:32
@zhou-hongyu zhou-hongyu changed the title first pass of adding family name and table name to reflector side [CONFIG-398] Reflector: query ctlstore_dml_ledger using shard fields (families, tables) Feb 22, 2024
@zhou-hongyu zhou-hongyu changed the title [CONFIG-398] Reflector: query ctlstore_dml_ledger using shard fields (families, tables) [CONFIG-398] Reflector: query ctlstore_dml_ledger using shard fields (families, tables) Feb 22, 2024
@zhou-hongyu zhou-hongyu marked this pull request as ready for review February 23, 2024 22:18
@zhou-hongyu zhou-hongyu requested a review from a team as a code owner February 23, 2024 22:18
}

if shardingTable != "" {
whereClause += fmt.Sprintf(" AND CONCAT(family_name,'___',table_name) IN $3")
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 have consulted Copilot and confirmed that using CONCAT will indeed slow down the query performance:
Screenshot 2024-02-26 at 6 30 28 PM

But I will keep it for now, leaving us two options to optimize:

  1. As suggested by Copilot, add an additional column family_table_concat beside family_name and table_name to the ledger table.
  2. Utilize composite key suggested by Erik.

Either way making necessary code changes doesn't feel like a too time-consuming task.

Copy link
Collaborator

@erikdw erikdw Feb 27, 2024

Choose a reason for hiding this comment

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

Or we can change the table column in the ledger table to be the fully-qualified name. Can just change the Executive code to write that instead. Will have to think for a bit whether we actually need the unqualified table name for some reason, but cannot quickly think of why we wouldn't be ok with it.

Copy link
Collaborator

@erikdw erikdw left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@erikdw erikdw merged commit a4407b8 into ldb-sharding Feb 27, 2024
7 of 8 checks passed
@erikdw erikdw deleted the hzhou/CONFIG-398-reflector-query-ctlstore-dml-ledger-using-shard-fields-families-tables branch February 27, 2024 19:56
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.

3 participants