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

Introduce sharding rules to MongoDB collections #689

Closed
wants to merge 12 commits into from
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,28 @@ jobs:
fail-on-alert: false
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-always: true

sharding_test:
name: sharding_test
runs-on: ubuntu-latest
steps:

- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Check out code
uses: actions/checkout@v4

- name: Get tools dependencies
run: make tools

- name: Stack
run: docker-compose -f build/docker/sharding/test/docker-compose.yml up --build -d

- name: Wait for 30 seconds until the DB cluster is ready
run: sleep 30s

- name: Run the tests with sharding tag
run: go test -tags sharding -race -v ./test/sharding/...
5 changes: 3 additions & 2 deletions admin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (c *Client) UpdateProject(
func (c *Client) ListDocuments(
ctx context.Context,
projectName string,
previousID string,
previousOffset types.DocRefKey,
pageSize int32,
isForward bool,
includeSnapshot bool,
Expand All @@ -257,7 +257,8 @@ func (c *Client) ListDocuments(
ctx,
&api.ListDocumentsRequest{
ProjectName: projectName,
PreviousId: previousID,
PreviousKey: previousOffset.Key.String(),
PreviousId: previousOffset.ID.String(),
PageSize: pageSize,
IsForward: isForward,
IncludeSnapshot: includeSnapshot,
Expand Down
2 changes: 1 addition & 1 deletion api/types/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Project struct {
Name string `json:"name"`

// Owner is the owner of this project.
Owner ID `json:"owner"`
Owner string `json:"owner"`

// AuthWebhookURL is the url of the authorization webhook.
AuthWebhookURL string `json:"auth_webhook_url"`
Expand Down
67 changes: 67 additions & 0 deletions api/types/resource_ref_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2023 The Yorkie Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package types

import (
"errors"
"fmt"
"strings"

"github.com/yorkie-team/yorkie/pkg/document/key"
)

// ErrInvalidDocRefKeySetInput is returned when the input of DocRefKey Set is invalid.
var ErrInvalidDocRefKeySetInput = errors.New("use the format 'docKey,docID' for the input")

// DocRefKey represents an identifier used to reference a document.
type DocRefKey struct {
Key key.Key
ID ID
}

// String returns the string representation of the given DocRefKey.
func (r *DocRefKey) String() string {
return fmt.Sprintf("Doc (%s.%s)", r.Key, r.ID)
}

// Set parses the given string (format: `{docKey},{docID}`) and assigns the values
// to the given DocRefKey.
func (r *DocRefKey) Set(v string) error {
parsed := strings.Split(v, ",")
if len(parsed) != 2 {
return ErrInvalidDocRefKeySetInput
}
r.Key = key.Key(parsed[0])
r.ID = ID(parsed[1])
return nil
}

// Type returns the type string of the given DocRefKey, used in cli help text.
func (r *DocRefKey) Type() string {
return "DocumentRefKey"
}

// ClientRefKey represents an identifier used to reference a client.
type ClientRefKey struct {
Key string
ID ID
}

// String returns the string representation of the given ClientRefKey.
func (r *ClientRefKey) String() string {
return fmt.Sprintf("Client (%s.%s)", r.Key, r.ID)
}
45 changes: 45 additions & 0 deletions api/types/resource_ref_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2023 The Yorkie Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package types_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

"github.com/yorkie-team/yorkie/api/types"
"github.com/yorkie-team/yorkie/pkg/document/key"
)

func TestResourceRefKey(t *testing.T) {
t.Run("DocRefKey Set test", func(t *testing.T) {
docKey := key.Key("docKey")
docID := types.ID("docID")
docRef := types.DocRefKey{}

// 01. Give an invalid input to Set.
err := docRef.Set("abc")
assert.ErrorIs(t, err, types.ErrInvalidDocRefKeySetInput)

// 02. Give a valid input to Set.
err = docRef.Set(fmt.Sprintf("%s,%s", docKey, docID))
assert.NoError(t, err)
assert.Equal(t, docRef.Key, docKey)
assert.Equal(t, docRef.ID, docID)
})
}
178 changes: 115 additions & 63 deletions api/yorkie/v1/admin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading