-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metabase: add benchmarks for precommit constraint
Change-Id: I4a01da1196504a695db98f5d249ba1bcce9ceff3
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2024 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package metabase | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// PrecommitConstraint exposes precommitConstraint for testing. | ||
type PrecommitConstraint precommitConstraint | ||
|
||
// PrecommitConstraintResult exposes precommitConstraintResult for testing. | ||
type PrecommitConstraintResult precommitConstraintResult | ||
|
||
// StmtRow exposes stmtRow for testing. | ||
type StmtRow stmtRow | ||
|
||
// PrecommitConstraint exposes precommitConstraint for testing. | ||
func (db *DB) PrecommitConstraint(ctx context.Context, opts PrecommitConstraint, tx StmtRow) (result PrecommitConstraintResult, err error) { | ||
r, err := db.precommitConstraint(ctx, precommitConstraint(opts), tx) | ||
return PrecommitConstraintResult(r), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (C) 2020 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package metabase_test | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"storj.io/common/testcontext" | ||
"storj.io/storj/satellite/metabase" | ||
"storj.io/storj/satellite/metabase/metabasetest" | ||
) | ||
|
||
func BenchmarkPrecommitConstraint(b *testing.B) { | ||
metabasetest.Bench(b, func(ctx *testcontext.Context, b *testing.B, db *metabase.DB) { | ||
baseObj := metabasetest.RandObjectStream() | ||
|
||
for i := 0; i < 500; i++ { | ||
metabasetest.CreateObject(ctx, b, db, metabasetest.RandObjectStream(), 0) | ||
} | ||
|
||
for i := 0; i < 10; i++ { | ||
baseObj.ObjectKey = metabase.ObjectKey("foo/" + strconv.Itoa(i)) | ||
metabasetest.CreateObject(ctx, b, db, baseObj, 0) | ||
|
||
baseObj.ObjectKey = metabase.ObjectKey("foo/prefixA/" + strconv.Itoa(i)) | ||
metabasetest.CreateObject(ctx, b, db, baseObj, 0) | ||
|
||
baseObj.ObjectKey = metabase.ObjectKey("foo/prefixB/" + strconv.Itoa(i)) | ||
metabasetest.CreateObject(ctx, b, db, baseObj, 0) | ||
} | ||
|
||
for i := 0; i < 50; i++ { | ||
baseObj.ObjectKey = metabase.ObjectKey("boo/foo" + strconv.Itoa(i) + "/object") | ||
metabasetest.CreateObject(ctx, b, db, baseObj, 0) | ||
} | ||
|
||
b.Run("unversioned", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_, err := db.PrecommitConstraint(ctx, metabase.PrecommitConstraint{ | ||
Location: metabase.ObjectLocation{ | ||
ProjectID: baseObj.ProjectID, | ||
BucketName: baseObj.BucketName, | ||
ObjectKey: "foo/5", | ||
}, | ||
Versioned: false, | ||
DisallowDelete: false, | ||
}, db.UnderlyingTagSQL()) | ||
require.NoError(b, err) | ||
} | ||
}) | ||
|
||
b.Run("versioned", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_, err := db.PrecommitConstraint(ctx, metabase.PrecommitConstraint{ | ||
Location: metabase.ObjectLocation{ | ||
ProjectID: baseObj.ProjectID, | ||
BucketName: baseObj.BucketName, | ||
ObjectKey: "foo/5", | ||
}, | ||
Versioned: true, | ||
DisallowDelete: false, | ||
}, db.UnderlyingTagSQL()) | ||
require.NoError(b, err) | ||
} | ||
}) | ||
}) | ||
} |