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

colibri: further improve sqlite reservation store #3794

Merged
merged 24 commits into from
Jul 8, 2020

Conversation

juagargi
Copy link
Contributor

@juagargi juagargi commented Jun 19, 2020

Improve how segments and end to end reservations are persisted
Document the database design at doc/ColibriService.md


This change is Reviewable

@juagargi juagargi changed the title WIP COLIBRI sqlite implementation part 3 COLIBRI sqlite implementation part 3 Jun 27, 2020
Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

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

Reviewed 22 of 22 files at r1.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @juagargi)


go/cs/reservation/reservationdbtest/reservationdbtest.go, line 668 at r1 (raw file):

			}
		}
		// rsvs = append(rsvs, rs...)

debug remains?


go/cs/reservation/sqlite/db.go, line 255 at r1 (raw file):

	deletedIndices := 0

	n, err := deleteExpiredIndices(ctx, x.db, now,

I think keeping it DRY here actually hurts readability.
I think it would be more readable, if you expand the function call here and directly do the calls.


go/lib/colibri/reservation/types.go, line 132 at r1 (raw file):

// ToRaw calls Read and returns a new allocated buffer with the ID serialized.
func (id *E2EID) ToRaw() []byte {
	buff := make([]byte, E2EIDLen)

buf

Copy link
Contributor Author

@juagargi juagargi left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @oncilla)


go/cs/reservation/reservationdbtest/reservationdbtest.go, line 668 at r1 (raw file):

Previously, Oncilla (Dominik Roos) wrote…

debug remains?

Done.


go/cs/reservation/sqlite/db.go, line 255 at r1 (raw file):

Previously, Oncilla (Dominik Roos) wrote…

I think keeping it DRY here actually hurts readability.
I think it would be more readable, if you expand the function call here and directly do the calls.

It's a fairly sized chunk of code to repeat it here. Also DeleteExpiredIndices clearly does twice deleteExpiredIndices. What is not clear IMO is what that function accepts as arguments.
I am adding several comments to improve readability. Please check if it is okay now.


go/lib/colibri/reservation/types.go, line 132 at r1 (raw file):

Previously, Oncilla (Dominik Roos) wrote…

buf

Done.

Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @juagargi)


go/cs/reservation/sqlite/db.go, line 255 at r1 (raw file):

Previously, juagargi (Juan A. Garcia Pardo) wrote…

It's a fairly sized chunk of code to repeat it here. Also DeleteExpiredIndices clearly does twice deleteExpiredIndices. What is not clear IMO is what that function accepts as arguments.
I am adding several comments to improve readability. Please check if it is okay now.

it would be something like:

	deletedIndices := 0
	err := db.DoInTx(ctx, x, func(ctx context.Context, tx *sql.Tx) error {
		rowIDs, rsvRowIDs, err := getExpiredIndexRowIDs(ctx, tx, now)
		if err != nil {
			return err
		}
		if len(rowIDs) == 0 {
			// if no index was deleted, nothing else to do
			return nil
		}
		// delete the segment indices pointed by rowIDs
		n, err := deleteE2EIndiciesFromRowIDs(ctx, tx, rowIDs)
		if err != nil {
			return err
		}
		deletedIndices = n
		// delete empty reservations touched by previous removal
		return deleteEmptyE2EReservations(ctx, tx, rsvRowIDs)
	})
	if err != nil {
		return 0, err
	}
	err := db.DoInTx(ctx, x, func(ctx context.Context, tx *sql.Tx) error {
		rowIDs, rsvRowIDs, err := getExpiredSegIndexRowIDs(ctx, tx, now)
		if err != nil {
			return err
		}
		if len(rowIDs) == 0 {
			// if no index was deleted, nothing else to do
			return nil
		}
		// delete the segment indices pointed by rowIDs
		n, err := deleteSegIndiciesFromRowIDs(ctx, tx, rowIDs)
		if err != nil {
			return err
		}
		deletedIndices += n
		// delete empty reservations touched by previous removal
		return deleteEmptySegReservations(ctx, tx, rsvRowIDs)
	})

or you could even do it in a single transaction.

Copy link
Contributor Author

@juagargi juagargi left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @oncilla)


go/cs/reservation/sqlite/db.go, line 255 at r1 (raw file):

Previously, Oncilla (Dominik Roos) wrote…

it would be something like:

	deletedIndices := 0
	err := db.DoInTx(ctx, x, func(ctx context.Context, tx *sql.Tx) error {
		rowIDs, rsvRowIDs, err := getExpiredIndexRowIDs(ctx, tx, now)
		if err != nil {
			return err
		}
		if len(rowIDs) == 0 {
			// if no index was deleted, nothing else to do
			return nil
		}
		// delete the segment indices pointed by rowIDs
		n, err := deleteE2EIndiciesFromRowIDs(ctx, tx, rowIDs)
		if err != nil {
			return err
		}
		deletedIndices = n
		// delete empty reservations touched by previous removal
		return deleteEmptyE2EReservations(ctx, tx, rsvRowIDs)
	})
	if err != nil {
		return 0, err
	}
	err := db.DoInTx(ctx, x, func(ctx context.Context, tx *sql.Tx) error {
		rowIDs, rsvRowIDs, err := getExpiredSegIndexRowIDs(ctx, tx, now)
		if err != nil {
			return err
		}
		if len(rowIDs) == 0 {
			// if no index was deleted, nothing else to do
			return nil
		}
		// delete the segment indices pointed by rowIDs
		n, err := deleteSegIndiciesFromRowIDs(ctx, tx, rowIDs)
		if err != nil {
			return err
		}
		deletedIndices += n
		// delete empty reservations touched by previous removal
		return deleteEmptySegReservations(ctx, tx, rsvRowIDs)
	})

or you could even do it in a single transaction.

Done.

@juagargi juagargi force-pushed the colibri.backend3 branch from bbde02d to 581d7ff Compare July 3, 2020 15:11
Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r3.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


go/cs/reservation/sqlite/db.go, line 255 at r1 (raw file):

Previously, juagargi (Juan A. Garcia Pardo) wrote…

Done.

fwiw, I think this reads nicely 👍

Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@oncilla
Copy link
Contributor

oncilla commented Jul 6, 2020

/rebase

@juagargi juagargi force-pushed the colibri.backend3 branch from bf62127 to 3207931 Compare July 8, 2020 09:53
Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r4.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@oncilla oncilla changed the title COLIBRI sqlite implementation part 3 colibri: further improve sqlite reservation store Jul 8, 2020
@oncilla oncilla merged commit 2b2f41f into scionproto:master Jul 8, 2020
@juagargi juagargi deleted the colibri.backend3 branch July 21, 2020 07:36
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.

2 participants