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

Clear presence when housekeeping process #936

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
5d48edb
Modify `clients.Deactivate` to handle presence clear
raararaara Jul 19, 2024
fb631fa
Resolve conflict
raararaara Jul 22, 2024
90cfe15
Fix invalid argument passing
hackerwins Jul 22, 2024
e496ad2
Fix lint warning
hackerwins Jul 22, 2024
a87a9f1
Add related test
raararaara Jul 22, 2024
1da3ec3
Add logic to prevent duplicate presence clear change
raararaara Jul 22, 2024
525d4c4
Simplify presenceChange clear condition
raararaara Jul 23, 2024
28b0db5
Add test related to duplicate presence clear
raararaara Jul 23, 2024
1c5b05c
Lint
raararaara Jul 23, 2024
e0b9fce
Fix test to return correct result
raararaara Jul 23, 2024
597b867
Add additional comments
raararaara Jul 23, 2024
e39b542
Cleanup code
raararaara Jul 23, 2024
74bca05
Cleanup code
raararaara Jul 23, 2024
3409bf1
Revise the deactivation logic
hackerwins Jul 23, 2024
e4ded21
Revert queries and test related to `DeactivateClient`
raararaara Jul 24, 2024
13211b1
Modify `clients.Deactivate` to load client within the method
raararaara Jul 26, 2024
cc14a6c
Fix rpcAddr to cover other testcases
raararaara Jul 26, 2024
ab278e7
Lint
raararaara Jul 26, 2024
17de638
Fix `ToClient` to allow token value to be received when creating clie…
raararaara Jul 29, 2024
532f87d
Lint
raararaara Jul 29, 2024
5ad0b89
Refactored `clients.Deactivate` to use `client.Detach`
raararaara Aug 1, 2024
6034b7d
Add gateway host to Yorkie deployment
raararaara Aug 6, 2024
5733c0e
Lint
raararaara Aug 6, 2024
c2da835
Modified client creation to be performed at `clients.Deactivate`
raararaara Aug 6, 2024
98d5938
Refactored comment to clarify APIhost determination logic based on en…
raararaara Aug 6, 2024
a1d8ed1
Move backend-gateway-addr to flag
hackerwins Aug 9, 2024
6619673
Added server token to ensure authorization for client deactivation du…
raararaara Aug 14, 2024
0aae9a0
Add systemService to handle perform background deactivation
raararaara Aug 19, 2024
3c5f5e1
Revert "Add systemService to handle perform background deactivation"
raararaara Aug 19, 2024
4ae640a
Add system server to handle perform housekeeping deactivation
raararaara Sep 24, 2024
9728100
Fix lint
raararaara Sep 24, 2024
c24411b
Fix lint proto
raararaara Sep 24, 2024
ab77581
Fix lint proto
raararaara Sep 24, 2024
60425b7
Modify buf.yaml temporarily to allow buf lint for CI test verification
raararaara Sep 24, 2024
1ea7a8d
Introduce system client
raararaara Sep 30, 2024
7366827
Modify to handle detach by http server
raararaara Oct 7, 2024
1bbbdb6
Remove RPC system server
raararaara Oct 7, 2024
669d3ef
Cleanup code
raararaara Oct 7, 2024
059fddd
Update `updated_at` only when there are operations in changes (#935)
window9u Jul 22, 2024
6a05607
Improve performance for creating crdt.TreeNode (#939)
m4ushold Jul 24, 2024
1791d7f
Update CHANGELOG.md for v0.4.28 (#942)
hackerwins Jul 25, 2024
b3f0362
Fix FindDocInfosByKeys when keys is empty (#945)
blurfx Jul 26, 2024
cee8d9a
Support basic account action for admin (#934)
gusah009 Jul 27, 2024
49bc08c
Update docker compose command to V2 (#950)
fourjae Aug 3, 2024
8ea4fa2
Handle panic during conversion to connectCode (#951)
blurfx Aug 5, 2024
e76544a
Update CHANGELOG.md for v0.4.29 (#953)
hackerwins Aug 5, 2024
39929ec
Add HTTP health check handler for server health monitoring (#952)
taeng0204 Aug 7, 2024
c8c744d
Update README.md
hackerwins Aug 8, 2024
38b6457
Show Server Version in Yorkie CLI (#938)
hyun98 Aug 9, 2024
7d189b6
Update CHANGELOG.md for v0.4.30 (#956)
hackerwins Aug 9, 2024
9a21c0c
Modify health check endpoint and add HEAD method (#958)
taeng0204 Aug 15, 2024
fa0be2d
[Revised] Fine-tuned CI Workflows in PR (#965)
krapie Aug 16, 2024
6910511
Add a metric to collect the number of background routines (#963)
kokodak Aug 19, 2024
f8f40fc
Fix invalid test case in FindDocInfosByKeys (#972)
kokodak Aug 21, 2024
b254db1
Update CHANGELOG.md for v0.4.31 (#973)
hackerwins Aug 21, 2024
895c828
Set `updated_at` with `created_at` when creating Document (#977)
window9u Sep 2, 2024
d383ed6
Add Concurrency Tests for Array Operations (#985)
cloneot Sep 2, 2024
25e0e16
Optimize FindChangeInfosBetweenServerSeqs to prevent unnecessary Quer…
kokodak Sep 2, 2024
ad8161c
Rename SetByIndex to ArraySet (#995)
hackerwins Sep 3, 2024
43a4340
Add Account Deletion and Change Password to CLI Commands (#983)
sigmaith Sep 3, 2024
10b87cf
Merge branch 'main' of https://github.com/yorkie-team/yorkie
raararaara Oct 7, 2024
c8ad4ab
Merge branch 'main' into housekeeping-remove-presence
raararaara Oct 7, 2024
e7221c9
Add missing param
raararaara Oct 7, 2024
b6eba52
Add system server configuration to ensure execute main test properly
raararaara Oct 7, 2024
62a461e
Add system server configuration to ensure execute main test properly
raararaara Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,098 changes: 1,098 additions & 0 deletions api/docs/yorkie/v1/system.openapi.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions build/charts/yorkie-cluster/templates/yorkie/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ spec:
"{{ .Values.yorkie.ports.rpcPort }}",
"--profiling-port",
"{{ .Values.yorkie.ports.profilingPort }}",
"--backend-gateway-host",
"{{ .Values.yorkie.gateway }}.{{ .Values.yorkie.namespace }}.svc.cluster.local",
]
ports:
- containerPort: {{ .Values.yorkie.ports.rpcPort }}
Expand Down
2 changes: 2 additions & 0 deletions build/charts/yorkie-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ yorkie:
name: yorkie
namespace: yorkie

gateway: yorkie-gateway

autoscaling:
enabled: false
replicaCount: 3
Expand Down
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ func (c *Client) Detach(ctx context.Context, doc *document.Document, options ...
return err
}

// TODO(raararaara): We need to revert the presence clearing from the local
// changes, if the server fails to detach the document.
res, err := c.client.DetachDocument(
ctx,
withShardKey(connect.NewRequest(&api.DetachDocumentRequest{
Expand Down
72 changes: 0 additions & 72 deletions cmd/yorkie/logout.go

This file was deleted.

13 changes: 13 additions & 0 deletions cmd/yorkie/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ func init() {
server.DefaultHostname,
"Yorkie Server Hostname",
)
cmd.Flags().StringVar(
&conf.Backend.GatewayAddr,
"backend-gateway-addr",
server.DefaultGatewayAddr,
"Gateway address",
)

//cmd.Flags().StringVar(
// &conf.Backend.SystemServerAddr,
// "backend-gateway-addr",
// server.DefaultSystemServerAddr,
// "Gateway address",
//)

rootCmd.AddCommand(cmd)
}
5 changes: 5 additions & 0 deletions pkg/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ func (d *Document) BroadcastEventHandlers() map[string]func(
return d.broadcastEventHandlers
}

// setInternalDoc sets the given internal document to this document.
func (d *Document) setInternalDoc(internalDoc *InternalDocument) {
d.doc = internalDoc
}

func messageFromMsgAndArgs(msgAndArgs ...interface{}) string {
if len(msgAndArgs) == 0 {
return ""
Expand Down
19 changes: 19 additions & 0 deletions pkg/document/internal_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ func (d *InternalDocument) Checkpoint() change.Checkpoint {
return d.checkpoint
}

// SyncCheckpoint syncs the checkpoint and the changeID with the given serverSeq
// and clientSeq.
func (d *InternalDocument) SyncCheckpoint(serverSeq int64, clientSeq uint32) {
d.changeID = change.NewID(
clientSeq,
serverSeq,
d.changeID.Lamport(),
d.changeID.ActorID(),
)
d.checkpoint = d.checkpoint.SyncClientSeq(clientSeq)
}

// HasLocalChanges returns whether this document has local changes or not.
func (d *InternalDocument) HasLocalChanges() bool {
return len(d.localChanges) > 0
Expand Down Expand Up @@ -372,3 +384,10 @@ func (d *InternalDocument) AddOnlineClient(clientID string) {
func (d *InternalDocument) RemoveOnlineClient(clientID string) {
d.onlineClients.Delete(clientID)
}

// ToDocument converts this document to Document.
func (d *InternalDocument) ToDocument() *Document {
doc := New(d.key)
doc.setInternalDoc(d)
return doc
}
16 changes: 16 additions & 0 deletions server/backend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ type Config struct {

// Hostname is yorkie server hostname. hostname is used by metrics.
Hostname string `yaml:"Hostname"`

// GatewayAddr is the address of the gateway server.
GatewayAddr string `yaml:"GatewayAddr"`

ServerToken string `yaml:"YorkieServerToken"`

SystemServerAddr string `yaml:"SystemServerAddr"`
}

// FetchGatewayAddr returns the address of the gateway server.
func (c *Config) FetchGatewayAddr(rpcAddr string) string {
if c.SystemServerAddr == "" {
return rpcAddr
}

return c.SystemServerAddr
}

// Validate validates this config.
Expand Down
7 changes: 0 additions & 7 deletions server/backend/database/memory/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,6 @@ func (d *DB) DeactivateClient(_ context.Context, refKey types.ClientRefKey) (*da
// the stored objects are returned instead of new objects. This can cause
// problems when directly modifying loaded objects. So, we need to DeepCopy.
clientInfo = clientInfo.DeepCopy()
for docID := range clientInfo.Documents {
if clientInfo.Documents[docID].Status == database.DocumentAttached {
if err := clientInfo.DetachDocument(docID); err != nil {
return nil, err
}
}
}
clientInfo.Deactivate()

if err := txn.Insert(tblClients, clientInfo); err != nil {
Expand Down
34 changes: 5 additions & 29 deletions server/backend/database/mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,39 +549,15 @@ func (c *Client) ActivateClient(ctx context.Context, projectID types.ID, key str
return &clientInfo, nil
}

// DeactivateClient deactivates the client of the given refKey and updates document statuses as detached.
// DeactivateClient deactivates the client of the given refKey.
func (c *Client) DeactivateClient(ctx context.Context, refKey types.ClientRefKey) (*database.ClientInfo, error) {
res := c.collection(ColClients).FindOneAndUpdate(ctx, bson.M{
"project_id": refKey.ProjectID,
"_id": refKey.ClientID,
}, bson.A{
bson.M{
"$set": bson.M{
"status": database.ClientDeactivated,
"updated_at": gotime.Now(),
"documents": bson.M{
"$arrayToObject": bson.M{
"$map": bson.M{
"input": bson.M{"$objectToArray": "$documents"},
"as": "doc",
"in": bson.M{
"k": "$$doc.k",
"v": bson.M{
"$cond": bson.M{
"if": bson.M{"$eq": bson.A{"$$doc.v.status", database.DocumentAttached}},
"then": bson.M{
"client_seq": 0,
"server_seq": 0,
"status": database.DocumentDetached,
},
"else": "$$doc.v",
},
},
},
},
},
},
},
}, bson.M{
"$set": bson.M{
"status": database.ClientDeactivated,
"updated_at": gotime.Now(),
},
}, options.FindOneAndUpdate().SetReturnDocument(options.After))

Expand Down
50 changes: 0 additions & 50 deletions server/backend/database/testcases/testcases.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,56 +676,6 @@ func RunActivateClientDeactivateClientTest(t *testing.T, db database.Database, p
assert.Equal(t, t.Name(), clientInfo.Key)
assert.Equal(t, database.ClientDeactivated, clientInfo.Status)
})

t.Run("ensure document detached when deactivate client test", func(t *testing.T) {
ctx := context.Background()

// 01. Create a client
clientInfo, err := db.ActivateClient(ctx, projectID, t.Name())
assert.NoError(t, err)
assert.Equal(t, t.Name(), clientInfo.Key)
assert.Equal(t, database.ClientActivated, clientInfo.Status)

// 02. Create documents and attach them to the client
for i := 0; i < 3; i++ {
docInfo, _ := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), helper.TestDocKey(t, i), true)
assert.NoError(t, clientInfo.AttachDocument(docInfo.ID, false))
clientInfo.Documents[docInfo.ID].ServerSeq = 1
clientInfo.Documents[docInfo.ID].ClientSeq = 1
assert.NoError(t, db.UpdateClientInfoAfterPushPull(ctx, clientInfo, docInfo))

result, err := db.FindClientInfoByRefKey(ctx, clientInfo.RefKey())
assert.Equal(t, result.Documents[docInfo.ID].Status, database.DocumentAttached)
assert.Equal(t, result.Documents[docInfo.ID].ServerSeq, int64(1))
assert.Equal(t, result.Documents[docInfo.ID].ClientSeq, uint32(1))
assert.NoError(t, err)
}

// 03. Remove one document
docInfo, err := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), helper.TestDocKey(t, 2), true)
assert.NoError(t, err)
assert.NoError(t, clientInfo.RemoveDocument(docInfo.ID))
assert.NoError(t, db.UpdateClientInfoAfterPushPull(ctx, clientInfo, docInfo))

// 04. Deactivate the client
result, err := db.DeactivateClient(ctx, types.ClientRefKey{
ProjectID: projectID,
ClientID: clientInfo.ID,
})
assert.NoError(t, err)

// 05. Check whether doc.Status is reflected properly.
// If it was `DocumentAttached`, it should be changed to `DocumentDetached`.
for i := 0; i < 2; i++ {
docInfo, err := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), helper.TestDocKey(t, i), true)
assert.NoError(t, err)
assert.Equal(t, result.Documents[docInfo.ID].Status, database.DocumentDetached)
}
// If it was `DocumentRemoved`, it should be remained `DocumentRemoved`.
docInfo, err = db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), helper.TestDocKey(t, 2), true)
assert.NoError(t, err)
assert.Equal(t, result.Documents[docInfo.ID].Status, database.DocumentRemoved)
})
}

// RunUpdateProjectInfoTest runs the UpdateProjectInfo tests for the given db.
Expand Down
Loading
Loading