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

chore(warehouse): use fastUUID with google UUID generation #2598

Merged
merged 19 commits into from
Nov 11, 2022

Conversation

achettyiitr
Copy link
Member

@achettyiitr achettyiitr commented Oct 19, 2022

Description

Use google's uuid, as gofrs can cause performance issues

Also, we have introduced one more utility called RandHex which generated a random string of 32 characters from UUID.
(The benefit here is that at some places where after getting the UUID string of 36 characters we used to replace -. Since we are doing extra computation of preparing the UUID string and replacing the -. The same functionality is being provided by RandHex.)

Notion Ticket

https://www.notion.so/rudderstacks/Fasf-UUID-4683365544654681aa04f69f790e05ce

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@codecov
Copy link

codecov bot commented Oct 19, 2022

Codecov Report

Base: 45.44% // Head: 45.47% // Increases project coverage by +0.02% 🎉

Coverage data is based on head (a354d89) compared to base (af2b5a7).
Patch coverage: 47.82% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2598      +/-   ##
==========================================
+ Coverage   45.44%   45.47%   +0.02%     
==========================================
  Files         289      289              
  Lines       47997    47999       +2     
==========================================
+ Hits        21814    21826      +12     
+ Misses      24796    24788       -8     
+ Partials     1387     1385       -2     
Impacted Files Coverage Δ
services/pgnotifier/pgnotifier.go 2.83% <0.00%> (ø)
warehouse/deltalake/deltalake.go 1.65% <0.00%> (ø)
warehouse/identity/identity.go 0.45% <0.00%> (ø)
warehouse/redshift/redshift.go 1.52% <0.00%> (ø)
warehouse/slave.go 1.08% <0.00%> (ø)
warehouse/testhelper/setup.go 0.00% <0.00%> (ø)
warehouse/upload.go 18.45% <0.00%> (ø)
warehouse/constraint.go 89.23% <100.00%> (ø)
warehouse/utils/utils.go 70.84% <100.00%> (+0.27%) ⬆️
warehouse/validations/helper.go 82.92% <100.00%> (-1.17%) ⬇️
... and 6 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@achettyiitr achettyiitr requested a review from lvrach October 31, 2022 13:12
@achettyiitr achettyiitr requested review from abhimanyubabbar, Jayachand and a team October 31, 2022 13:19
@achettyiitr achettyiitr marked this pull request as ready for review October 31, 2022 13:34
warehouse/bigquery/bigquery.go Outdated Show resolved Hide resolved
warehouse/utils/utils.go Outdated Show resolved Hide resolved
warehouse/utils/utils.go Outdated Show resolved Hide resolved
@achettyiitr achettyiitr requested review from lvrach and a team October 31, 2022 15:11
Copy link
Member

@lvrach lvrach left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my comments

@lvrach lvrach requested a review from a team November 8, 2022 11:19
Copy link
Contributor

@abhimanyubabbar abhimanyubabbar left a comment

Choose a reason for hiding this comment

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

Overall the changes looks good. 👍🏼 LGTM
I have just one comment on the motivation behind creation of RandomHex() function.

prefix := StagingTablePrefix(provider)
stagingTableName := fmt.Sprintf(`%s%s_%s`, prefix, tableName, randomNess)
return misc.TruncateStr(stagingTableName, tableNameLimit)
}

// RandHex returns a random hex string of length 32
func RandHex() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any improvement in this function in terms of speed or uniqueness over the other function ? Just curious to understand the motivation behind it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Actually, UUID.string() is processing for 36 bytes. We are ignoring the - present by replacing it using strings.ReplaceAll(uuid.Must(uuid.NewV4()).String(), "-", ""). We can just probably call hex.Encode which can just populate the 32 bytes.

const Size = 16
type UUID [Size]byte
func (u UUID) String() string {
	buf := make([]byte, 36)

	hex.Encode(buf[0:8], u[0:4])
	buf[8] = '-'
	hex.Encode(buf[9:13], u[4:6])
	buf[13] = '-'
	hex.Encode(buf[14:18], u[6:8])
	buf[18] = '-'
	hex.Encode(buf[19:23], u[8:10])
	buf[23] = '-'
	hex.Encode(buf[24:], u[10:])

	return string(buf)
}

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

Successfully merging this pull request may close these issues.

3 participants