Skip to content

Conversation

@khanhtc1202
Copy link
Member

@khanhtc1202 khanhtc1202 commented Feb 25, 2022

What this PR does / why we need it:

This PR introduces a way to merge raw data for multiple shards stored objects. I defined a new interface ShardDecoder, which will be used in case of building object from fetched data in filedb.

The PR also contains the implementation of the ShardDecoder interface for only commandCollection since the Command model is the only model which is multiple shards stored and there is a collision on its field named Status (should be stored in 2 shards: agent and piped)

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.55%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/datastore/commandstore.go commandCollection.Decode -- 87.50% +87.50%
pkg/datastore/filedb/codec.go decode -- 0.00% +0.00%
pkg/datastore/filedb/codec.go merge -- 83.33% +83.33%
pkg/datastore/filedb/filedb.go WithLogger -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go NewFileDB -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.fetch -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Find -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Get -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Create -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Update -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Close -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go makeHotStorageFilePath -- 0.00% +0.00%
pkg/datastore/commandstore.go commandCollection.ListInUsedShards 0.00% 100.00% +100.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.55%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/datastore/commandstore.go commandCollection.Decode -- 87.50% +87.50%
pkg/datastore/filedb/codec.go decode -- 0.00% +0.00%
pkg/datastore/filedb/codec.go merge -- 83.33% +83.33%
pkg/datastore/filedb/filedb.go WithLogger -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go NewFileDB -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.fetch -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Find -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Get -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Create -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Update -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Close -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go makeHotStorageFilePath -- 0.00% +0.00%
pkg/datastore/commandstore.go commandCollection.ListInUsedShards 0.00% 100.00% +100.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.55%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/datastore/commandstore.go commandCollection.Decode -- 87.50% +87.50%
pkg/datastore/filedb/codec.go decode -- 0.00% +0.00%
pkg/datastore/filedb/codec.go merge -- 83.33% +83.33%
pkg/datastore/filedb/filedb.go WithLogger -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go NewFileDB -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.fetch -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Find -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Get -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Create -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Update -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Close -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go makeHotStorageFilePath -- 0.00% +0.00%
pkg/datastore/commandstore.go commandCollection.ListInUsedShards 0.00% 100.00% +100.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.55%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/datastore/commandstore.go commandCollection.Decode -- 87.50% +87.50%
pkg/datastore/filedb/codec.go decode -- 0.00% +0.00%
pkg/datastore/filedb/codec.go merge -- 83.33% +83.33%
pkg/datastore/filedb/filedb.go WithLogger -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go NewFileDB -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.fetch -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Find -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Get -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Create -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Update -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Close -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go makeHotStorageFilePath -- 0.00% +0.00%
pkg/datastore/commandstore.go commandCollection.ListInUsedShards 0.00% 100.00% +100.00%

Copy link
Member

@nghialv nghialv left a comment

Choose a reason for hiding this comment

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

Look neat!
Just some nits, please check them.

return json.Unmarshal(parts[0], v)
}

// TODO: Add merge based on UpdatedAt field in case there are multiple parts of object are fetched.
Copy link
Member

Choose a reason for hiding this comment

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

Please close this issue once this PR got merged.

Copy link
Member Author

Choose a reason for hiding this comment

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

there is no issue like that, since I used the /todo skip command last time 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your confirmation. 👍

}
}
// TODO: Find a better way to set value of field UpdatedAt.
reflect.ValueOf(e).Elem().FieldByName("UpdatedAt").SetInt(latest)
Copy link
Member

Choose a reason for hiding this comment

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

We can also define a updatedAtSetter interface beside updatedAtGetter as above to cast and set.
We just use this reflect magic in case it is not castable.

Copy link
Member Author

Choose a reason for hiding this comment

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

in that case, we have to implement SetUpdatedAt for all models struct since the code generated by protobjf does not contain that function, which a bit odd to me, is that okay?
ref: golang/protobuf#65

Copy link
Member

Choose a reason for hiding this comment

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

in that case, we have to implement SetUpdatedAt for all models struct since the code generated by protobjf does not contain that function

Yes, I see. I think that is fine.

Copy link
Member

Choose a reason for hiding this comment

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

But you can note that way to your TODO and deal with that later.
We need a workable version first before a perfect one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed by 7b05be3 🙏

@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. Find a better way to set value of field UpdatedAt.

// TODO: Find a better way to set value of field UpdatedAt.
reflect.ValueOf(e).Elem().FieldByName("UpdatedAt").SetInt(latest)
return nil
}

This was created by todo plugin since "TODO:" was found in 953b0e0 when #3316 was merged. cc: @khanhtc1202.

@pipecd-bot
Copy link
Collaborator

GO_LINTER

The following files are not gofmt-ed. By commenting /golinter fmt, the formatted one will be appended to this pull request automatically.

pkg/datastore/filedb/codec.go
--- pkg/datastore/filedb/codec.go.orig
+++ pkg/datastore/filedb/codec.go
@@ -29,12 +29,12 @@
 	if ok {
 		return dcol.Decode(e, parts...)
 	}
-	
+
 	// In case it's single part contained object, unmarshal it directly.
 	if len(parts) == 1 {
 		return json.Unmarshal(parts[0], e)
 	}
-	
+
 	return merge(e, parts...)
 }
 

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.55%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/datastore/commandstore.go commandCollection.Decode -- 87.50% +87.50%
pkg/datastore/filedb/codec.go decode -- 0.00% +0.00%
pkg/datastore/filedb/codec.go merge -- 83.33% +83.33%
pkg/datastore/filedb/filedb.go WithLogger -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go NewFileDB -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.fetch -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Find -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Get -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Create -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Update -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go FileDB.Close -- 0.00% +0.00%
pkg/datastore/filedb/filedb.go makeHotStorageFilePath -- 0.00% +0.00%
pkg/datastore/commandstore.go commandCollection.ListInUsedShards 0.00% 100.00% +100.00%

@pipecd-bot
Copy link
Collaborator

GO_LINTER

The following files are not gofmt-ed. By commenting /golinter fmt, the formatted one will be appended to this pull request automatically.

pkg/datastore/filedb/codec.go
--- pkg/datastore/filedb/codec.go.orig
+++ pkg/datastore/filedb/codec.go
@@ -28,12 +28,12 @@
 	if ok {
 		return dcol.Decode(e, parts...)
 	}
-	
+
 	// In case it's single part contained object, unmarshal it directly.
 	if len(parts) == 1 {
 		return json.Unmarshal(parts[0], e)
 	}
-	
+
 	return merge(e, parts...)
 }
 

@nghialv
Copy link
Member

nghialv commented Feb 28, 2022

/golinter fmt

@nghialv
Copy link
Member

nghialv commented Feb 28, 2022

Looks neat!
/lgtm

@knanao
Copy link
Member

knanao commented Feb 28, 2022

Pretty good!
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by knanao.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit fcff1de into master Feb 28, 2022
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.

5 participants