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

File References Pagination #273

Merged
merged 10 commits into from
Aug 1, 2021
Merged

File References Pagination #273

merged 10 commits into from
Aug 1, 2021

Conversation

lpoli
Copy link
Contributor

@lpoli lpoli commented Jul 28, 2021

ISSUE

This branch solves the above issues by paginating File References which is used to construct ObjectTree, ObjectPath and ReferencePath. I've created new handler that provides paginated fileRefs.
There are three types of fileRefs: regular(undeleted refs), updated(updated refs compared to some given time) and deleted(deleted refs compared to some given time) which is crucial to construct local Tree cache to Add, Update and Delete tree nodes.

Pagination is done using alternative of offset https://blog.jooq.org/2013/10/26/faster-sql-paging-with-jooq-using-the-seek-method/
This makes use of indexes which significantly improves search performance.

Default and maximum pageLimit is 100 rows(about 50KB to 100KB json response). Client can request to obtain single reference with pageLimit 1. GoSdk work is in progress which serves as validating consensus of fileRefs. So that means actual tree construction is upto the application that is build upon gosdk; For example, zboxCli, 0fs, s3fs, ipfs, etc.

@shravanshetty1 shravanshetty1 requested review from kushthedude and removed request for vivekv96 and shravanshetty1 July 28, 2021 14:46
Copy link
Contributor

@kushthedude kushthedude left a comment

Choose a reason for hiding this comment

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

Following is a review at first glance, will take a deeper look at the logic tonight.
Can you also add tests for the pagination?

code/go/0chain.net/blobbercore/handler/handler.go Outdated Show resolved Hide resolved
UpdatedAt time.Time `gorm:"column:updated_at" dirlist:"updated_at" filelist:"updated_at"`

DeletedAt gorm.DeletedAt `gorm:"column:deleted_at"` // soft deletion
ID int64 `gorm:"column:id;primary_key" json:"id,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add json annotations explicitly? Gorm handles the json naming imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gives flexibility and also I am not sure about Gorm handling json naming. It supports json dataTypes but it always fills struct fields with its value and its easy to use it with json tag.

Copy link
Contributor

Choose a reason for hiding this comment

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

json column field is used when we unmarshal an interface to the following dataType, but since we already have gorm annotation, gorm has default serialising strategy as snake_case hence I said this change is redundant.

Copy link
Contributor

@kushthedude kushthedude left a comment

Choose a reason for hiding this comment

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

I don't have context on 0fs and the pagination followed here, according to the original issue the need was to have /v1/file/list/{allocation} accept query params & support pagination. Since I am still new to the project, I have just pointed out the general golang improvements.

code/go/0chain.net/blobbercore/handler/storage_handler.go Outdated Show resolved Hide resolved
code/go/0chain.net/blobbercore/handler/storage_handler.go Outdated Show resolved Hide resolved
@lpoli
Copy link
Contributor Author

lpoli commented Jul 29, 2021

Following is a review at first glance, will take a deeper look at the logic tonight.
Can you also add tests for the pagination?

Can I add it later after completing 0FS?
Should not take long

@lpoli lpoli requested a review from kushthedude July 29, 2021 11:37
@kushthedude
Copy link
Contributor

@lpoli resolve the conflicts, else lgtm

Copy link
Contributor

@kushthedude kushthedude left a comment

Choose a reason for hiding this comment

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

Hey @lpoli, CI is complaining will you please check into it, also if you like let's make this change too, #273 (comment) either is fine with me 😅

@lpoli
Copy link
Contributor Author

lpoli commented Aug 1, 2021

Hey @lpoli, CI is complaining will you please check into it, also if you like let's make this change too, #273 (comment) either is fine with me sweat_smile

CI test is error is fixed.
About json tag I say lets use json tag as I could not find explicit method that gorm provides to convert row data to json data. Also I checked if json.Marshall/Unmarshall could use other tag(gorm in this case) but in vain.

@lpoli lpoli merged commit fd367ed into master Aug 1, 2021
@@ -34,6 +34,14 @@ type ReferencePathResult struct {
LatestWM *writemarker.WriteMarker `json:"latest_write_marker"`
}

type RefResult struct {
TotalPages int `json:"total_pages"`
NewOffsetPath string `json:"offsetPath,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add some documentation about what is NewOffsetPath/NewoffsetDate? it is confused there without any comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

total_pages is snake_case, and offsetPath is lower_case. should we use snake_case only?

Copy link
Contributor

Choose a reason for hiding this comment

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

and the field name is NewOffsetPath, but it is offsetPath in json. why they are different?

"github.com/0chain/blobber/code/go/0chain.net/core/common"
)

func checkValidDate(s string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about Timezone? it will be an issue if client send date with local time zone.

func GetUpdatedRefs(ctx context.Context, allocationID, path, offsetPath, _type, updatedDate, offsetDate string, level, pageLimit int) (refs *[]Ref, totalPages int, newOffsetPath, newOffsetDate string, err error) {
var totalRows int64
var pRefs []Ref
db := datastore.GetStore().GetDB()
Copy link
Contributor

@cnlangzi cnlangzi Aug 27, 2021

Choose a reason for hiding this comment

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

Yes.db code smells off. but i have not idea yet.

@cnlangzi
Copy link
Contributor

cnlangzi commented Aug 28, 2021

requested changes will be fixed on #325

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

Successfully merging this pull request may close these issues.

3 participants