Skip to content

Commit

Permalink
[post-rebase] Revert "status" back to "state" in field names
Browse files Browse the repository at this point in the history
  • Loading branch information
arielshaqed committed Nov 25, 2020
1 parent 40fec4b commit d55eb5d
Showing 1 changed file with 75 additions and 13 deletions.
88 changes: 75 additions & 13 deletions catalog/mvcc/cataloger_export.go
Expand Up @@ -14,13 +14,79 @@ import (
"github.com/treeverse/lakefs/logging"
)

func (c *cataloger) GetExportConfigurationForBranch(repository string, branch string) (catalog.ExportConfiguration, error) {
// ExportConfiguration describes the export configuration of a branch, as passed on wire, used
// internally, and stored in DB.
type ExportConfiguration struct {
Path string `db:"export_path" json:"export_path"`
StatusPath string `db:"export_status_path" json:"export_status_path"`
LastKeysInPrefixRegexp pq.StringArray `db:"last_keys_in_prefix_regexp" json:"last_keys_in_prefix_regexp"`
IsContinuous bool `db:"continuous" json:"is_continuous"`
}

// ExportConfigurationForBranch describes how to export BranchID. It is stored in the database.
// Unfortunately golang sql doesn't know about embedded structs, so you get a useless copy of
// ExportConfiguration embedded here.
type ExportConfigurationForBranch struct {
Repository string `db:"repository"`
Branch string `db:"branch"`

Path string `db:"export_path"`
StatusPath string `db:"export_status_path"`
LastKeysInPrefixRegexp pq.StringArray `db:"last_keys_in_prefix_regexp"`
IsContinuous bool `db:"continuous"`
}

type CatalogBranchExportStatus string

const (
ExportStatusInProgress = CatalogBranchExportStatus("in-progress")
ExportStatusSuccess = CatalogBranchExportStatus("exported-successfully")
ExportStatusFailed = CatalogBranchExportStatus("export-failed")
ExportStatusRepaired = CatalogBranchExportStatus("export-repaired")
ExportStatusUnknown = CatalogBranchExportStatus("[unknown]")
)

// ExportStatus describes the current export status of a branch, as passed on wire, used
// internally, and stored in DB.
type ExportStatus struct {
CurrentRef string `db:"current_ref"`
State CatalogBranchExportStatus `db:"state"`
}

var ErrBadTypeConversion = errors.New("bad type")

// nolint: stylecheck
func (dst *CatalogBranchExportStatus) Scan(src interface{}) error {
var sc CatalogBranchExportStatus
switch s := src.(type) {
case string:
sc = CatalogBranchExportStatus(strings.ToLower(s))
case []byte:
sc = CatalogBranchExportStatus(strings.ToLower(string(s)))
default:
return fmt.Errorf("cannot convert %T to CatalogBranchExportStatus: %w", src, ErrBadTypeConversion)
}

if !(sc == ExportStatusInProgress || sc == ExportStatusSuccess || sc == ExportStatusFailed) {
// not a failure, "just" be a newer enum value than known
*dst = ExportStatusUnknown
return nil
}
*dst = sc
return nil
}

func (src CatalogBranchExportStatus) Value() (driver.Value, error) {
return string(src), nil
}

func (c *cataloger) GetExportConfigurationForBranch(repository string, branch string) (ExportConfiguration, error) {
ret, err := c.db.Transact(func(tx db.Tx) (interface{}, error) {
branchID, err := c.getBranchIDCache(tx, repository, branch)
var ret catalog.ExportConfiguration
if err != nil {
return nil, err
return nil, fmt.Errorf("repository %s branch %s: %w", repository, branch, err)
}
var ret ExportConfiguration
err = c.db.Get(&ret,
`SELECT export_path, export_status_path, last_keys_in_prefix_regexp, continuous
FROM catalog_branches_export
Expand Down Expand Up @@ -95,11 +161,7 @@ func (c *cataloger) GetExportState(repo string, branch string) (catalog.ExportSt

func (c *cataloger) ExportStateSet(repo, branch string, cb ExportStateCallback) error {
_, err := c.db.Transact(db.Void(func(tx db.Tx) error {
var res struct {
CurrentRef string
Status catalog.CatalogBranchExportStatus
ErrorMessage *string
}
var res catalog.ExportState

branchID, err := c.getBranchIDCache(tx, repo, branch)
if err != nil {
Expand All @@ -116,7 +178,7 @@ func (c *cataloger) ExportStateSet(repo, branch string, cb ExportStateCallback)
return fmt.Errorf("ExportStateMarkStart: failed to get existing state: %w", err)
}
oldRef := res.CurrentRef
oldStatus := res.Status
oldStatus := res.State

l := logging.Default().WithFields(logging.Fields{
"old_ref": oldRef,
Expand All @@ -142,15 +204,15 @@ func (c *cataloger) ExportStateSet(repo, branch string, cb ExportStateCallback)
l.Info("insert on DB")
tag, err = tx.Exec(`
INSERT INTO catalog_branches_export_state (branch_id, current_ref, state, error_message)
VALUES ($1, $2, 'in-progress', $3)`,
branchID, newRef, newMessage)
VALUES ($1, $2, $3, $4)`,
branchID, newRef, newStatus, newMessage)
} else {
l.Info("update on DB")
tag, err = tx.Exec(`
UPDATE catalog_branches_export_state
SET current_ref=$2, state='in-progress', error_message=NULL
SET current_ref=$2, state=$3, error_message=$4
WHERE branch_id=$1`,
branchID, newRef)
branchID, newRef, newStatus, newMessage)
}
if err != nil {
return err
Expand Down

0 comments on commit d55eb5d

Please sign in to comment.