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

[PSL-1210] make improvements in multi-vol-reg flow #895

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 10 additions & 9 deletions common/storage/ticketstore/activation_attempts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ type ActivationAttemptsQueries interface {
InsertActivationAttempt(attempt types.ActivationAttempt) (int64, error)
UpdateActivationAttempt(attempt types.ActivationAttempt) (int64, error)
GetActivationAttemptByID(id int) (*types.ActivationAttempt, error)
GetActivationAttemptsByFileID(fileID string) ([]*types.ActivationAttempt, error)
GetActivationAttemptsByFileIDAndBaseFileID(fileID, baseFileID string) ([]*types.ActivationAttempt, error)
}

// InsertActivationAttempt insert a new activation attempt into the activation_attempts table
func (s *TicketStore) InsertActivationAttempt(attempt types.ActivationAttempt) (int64, error) {
const insertQuery = `
INSERT INTO activation_attempts (
file_id, activation_attempt_at, is_successful, error_message, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?)
file_id, base_file_id, activation_attempt_at, is_successful, error_message, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?)
RETURNING id;`

var id int64
err := s.db.QueryRow(insertQuery,
attempt.FileID, attempt.ActivationAttemptAt,
attempt.FileID, attempt.BaseFileID, attempt.ActivationAttemptAt,
attempt.IsSuccessful, attempt.ErrorMessage, time.Now().UTC(), time.Now().UTC()).Scan(&id)
if err != nil {
return 0, err
Expand All @@ -35,7 +35,7 @@ func (s *TicketStore) InsertActivationAttempt(attempt types.ActivationAttempt) (
func (s *TicketStore) UpdateActivationAttempt(attempt types.ActivationAttempt) (int64, error) {
const updateQuery = `
UPDATE activation_attempts
SET activation_attempt_at = ?, is_successful = ?, error_message = ?, updated_at = ?
SET activation_attempt_at = ?, is_successful = ?, error_message = ?, updated_at = ?, is_confirmed=?
WHERE id = ? AND file_id = ?
RETURNING id`

Expand All @@ -45,6 +45,7 @@ func (s *TicketStore) UpdateActivationAttempt(attempt types.ActivationAttempt) (
attempt.IsSuccessful,
attempt.ErrorMessage,
time.Now().UTC(),
attempt.IsConfirmed,
attempt.ID,
attempt.FileID).Scan(&id)
if err != nil {
Expand Down Expand Up @@ -74,14 +75,14 @@ func (s *TicketStore) GetActivationAttemptByID(id int) (*types.ActivationAttempt
return &attempt, nil
}

// GetActivationAttemptsByFileID retrieves activation attempts by file_id from the activation_attempts table
func (s *TicketStore) GetActivationAttemptsByFileID(fileID string) ([]*types.ActivationAttempt, error) {
// GetActivationAttemptsByFileIDAndBaseFileID retrieves activation attempts by file_id from the activation_attempts table
func (s *TicketStore) GetActivationAttemptsByFileIDAndBaseFileID(fileID, baseFileID string) ([]*types.ActivationAttempt, error) {
const selectQuery = `
SELECT id, file_id, activation_attempt_at, is_successful, error_message
FROM activation_attempts
WHERE file_id = ?;`
WHERE file_id = ? and base_file_id=?;`

rows, err := s.db.Query(selectQuery, fileID)
rows, err := s.db.Query(selectQuery, fileID, baseFileID)
if err != nil {
return nil, err
}
Expand Down
23 changes: 12 additions & 11 deletions common/storage/ticketstore/registration_attempts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ type RegistrationAttemptsQueries interface {
InsertRegistrationAttempt(attempt types.RegistrationAttempt) (int64, error)
UpdateRegistrationAttempt(attempt types.RegistrationAttempt) (int64, error)
GetRegistrationAttemptByID(id int) (*types.RegistrationAttempt, error)
GetRegistrationAttemptsByFileID(fileID string) ([]*types.RegistrationAttempt, error)
GetRegistrationAttemptsByFileIDAndBaseFileID(fileID, baseFileID string) ([]*types.RegistrationAttempt, error)
}

// InsertRegistrationAttempt insert a new registration attempt into the registration_attempts table
func (s *TicketStore) InsertRegistrationAttempt(attempt types.RegistrationAttempt) (int64, error) {
const insertQuery = `
INSERT INTO registration_attempts (
file_id, reg_started_at, processor_sns, finished_at, is_successful, error_message, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
file_id, base_file_id, reg_started_at, processor_sns, finished_at, is_successful, error_message, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING id;`

var id int64
err := s.db.QueryRow(insertQuery,
attempt.FileID, attempt.RegStartedAt, attempt.ProcessorSNS,
attempt.FileID, attempt.BaseFileID, attempt.RegStartedAt, attempt.ProcessorSNS,
attempt.FinishedAt, attempt.IsSuccessful, attempt.ErrorMessage, time.Now().UTC(), time.Now().UTC()).Scan(&id)
if err != nil {
return 0, err
Expand All @@ -40,14 +40,15 @@ func (s *TicketStore) UpdateRegistrationAttempt(attempt types.RegistrationAttemp
finished_at = ?,
is_successful = ?,
error_message = ?,
is_confirmed=?,
updated_at = ?
WHERE id = ? AND file_id = ?
RETURNING id;`

var id int64
err := s.db.QueryRow(updateQuery,
attempt.RegStartedAt, attempt.ProcessorSNS, attempt.FinishedAt,
attempt.IsSuccessful, attempt.ErrorMessage, time.Now().UTC(),
attempt.IsSuccessful, attempt.ErrorMessage, attempt.IsConfirmed, time.Now().UTC(),
attempt.ID, attempt.FileID).Scan(&id)
if err != nil {
return 0, err
Expand Down Expand Up @@ -77,15 +78,15 @@ func (s *TicketStore) GetRegistrationAttemptByID(id int) (*types.RegistrationAtt
return &attempt, nil
}

// GetRegistrationAttemptsByFileID retrieves registration attempts by file_id from the registration_attempts table
func (s *TicketStore) GetRegistrationAttemptsByFileID(fileID string) ([]*types.RegistrationAttempt, error) {
// GetRegistrationAttemptsByFileIDAndBaseFileID retrieves registration attempts by file_id and baseFileID from the registration_attempts table
func (s *TicketStore) GetRegistrationAttemptsByFileIDAndBaseFileID(fileID, baseFileID string) ([]*types.RegistrationAttempt, error) {
const selectQuery = `
SELECT id, file_id, reg_started_at, processor_sns, finished_at,
SELECT id, file_id, base_file_id, reg_started_at, processor_sns, finished_at,
is_successful, error_message
FROM registration_attempts
WHERE file_id = ?;`
WHERE file_id = ? and base_file_id=?;`

rows, err := s.db.Query(selectQuery, fileID)
rows, err := s.db.Query(selectQuery, fileID, baseFileID)
if err != nil {
return nil, err
}
Expand All @@ -95,7 +96,7 @@ func (s *TicketStore) GetRegistrationAttemptsByFileID(fileID string) ([]*types.R
for rows.Next() {
var attempt types.RegistrationAttempt
err := rows.Scan(
&attempt.ID, &attempt.FileID, &attempt.RegStartedAt, &attempt.ProcessorSNS,
&attempt.ID, &attempt.FileID, &attempt.BaseFileID, &attempt.RegStartedAt, &attempt.ProcessorSNS,
&attempt.FinishedAt, &attempt.IsSuccessful, &attempt.ErrorMessage)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions common/storage/ticketstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ const createRegistrationAttemptsTable string = `
CREATE TABLE IF NOT EXISTS registration_attempts (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
file_id TEXT NOT NULL,
base_file_id TEXT NOT NULL,
reg_started_at DATETIME,
processor_sns TEXT,
finished_at DATETIME,
is_successful BOOLEAN,
is_confirmed BOOLEAN,
error_message TEXT,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL
Expand All @@ -55,8 +57,10 @@ const createActivationAttemptsTable string = `
CREATE TABLE IF NOT EXISTS activation_attempts (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
file_id TEXT NOT NULL,
base_file_id TEXT NOT NULL,
activation_attempt_at DATETIME,
is_successful BOOLEAN,
is_confirmed BOOLEAN,
error_message TEXT,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL
Expand Down
15 changes: 15 additions & 0 deletions common/types/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,36 @@ type Files []*File
type RegistrationAttempt struct {
ID int
FileID string
BaseFileID string
RegStartedAt time.Time
ProcessorSNS string
FinishedAt time.Time
IsSuccessful bool
IsConfirmed bool
ErrorMessage string
}

type ActivationAttempt struct {
ID int
FileID string
BaseFileID string
ActivationAttemptAt time.Time
IsSuccessful bool
IsConfirmed bool
ErrorMessage string
}

func (fs Files) GetUnconcludedFiles() (Files, error) {
var unconcludedFiles Files
for _, f := range fs {
if !f.IsConcluded {
unconcludedFiles = append(unconcludedFiles, f)
}
}

return unconcludedFiles, nil
}

func (fs Files) GetBase() *File {
for _, f := range fs {
if f.FileIndex == "0" {
Expand Down
4 changes: 1 addition & 3 deletions walletnode/api/design/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ var File = Type("File", func() {
Attribute("upload_timestamp", String, "Upload Timestamp in datetime format", func() {
Format(FormatDateTime)
})
Attribute("path", String, "Path to the file")
Attribute("file_index", String, "Index of the file")
Attribute("base_file_id", String, "Base File ID")
Attribute("task_id", String, "Task ID")
Expand All @@ -448,14 +447,13 @@ var File = Type("File", func() {
Attribute("hash_of_original_big_file", String, "Hash of the Original Big File")
Attribute("name_of_original_big_file_with_ext", String, "Name of the Original Big File with Extension")
Attribute("size_of_original_big_file", Float64, "Size of the Original Big File")
Attribute("data_type_of_original_big_file", String, "Data Type of the Original Big File")
Attribute("start_block", Int32, "Start Block")
Attribute("done_block", Int, "Done Block")
Attribute("registration_attempts", ArrayOf(RegistrationAttempt), "List of registration attempts")
Attribute("activation_attempts", ArrayOf(ActivationAttempt), "List of activation attempts")
Required("file_id", "task_id", "upload_timestamp", "base_file_id", "registration_attempts", "activation_attempts",
"req_burn_txn_amount", "req_amount", "cascade_metadata_ticket_id", "hash_of_original_big_file", "name_of_original_big_file_with_ext",
"size_of_original_big_file", "data_type_of_original_big_file")
"size_of_original_big_file")
})

var RegistrationAttempt = Type("RegistrationAttempt", func() {
Expand Down
8 changes: 0 additions & 8 deletions walletnode/api/gen/cascade/service.go

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

7 changes: 0 additions & 7 deletions walletnode/api/gen/cascade/views/view.go

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

4 changes: 2 additions & 2 deletions walletnode/api/gen/http/cascade/client/cli.go

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

2 changes: 0 additions & 2 deletions walletnode/api/gen/http/cascade/client/encode_decode.go

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

7 changes: 0 additions & 7 deletions walletnode/api/gen/http/cascade/client/types.go

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

2 changes: 0 additions & 2 deletions walletnode/api/gen/http/cascade/server/encode_decode.go

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

4 changes: 0 additions & 4 deletions walletnode/api/gen/http/cascade/server/types.go

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

Loading
Loading