Skip to content

Commit

Permalink
Post-rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arielshaqed committed Nov 25, 2020
1 parent 5e77681 commit 74527c9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 108 deletions.
24 changes: 23 additions & 1 deletion catalog/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
"time"

"github.com/treeverse/lakefs/db"
"github.com/lib/pq"
)

const (
Expand Down Expand Up @@ -145,6 +145,28 @@ type Cataloger interface {
// ExportStateCallback returns the new ref, state and message regarding the old ref and state
type ExportStateCallback func(oldRef string, state CatalogBranchExportStatus) (newRef string, newState CatalogBranchExportStatus, newMessage *string, err 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 PostCommitFunc = func(ctx context.Context, repo, branch string, commitLog *CommitLog) error
type PostMergeFunc = func(ctx context.Context, repo, branch string, mergeResult *MergeResult) error

Expand Down
35 changes: 3 additions & 32 deletions catalog/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,8 @@ import (
"database/sql/driver"
"fmt"
"strings"

"github.com/lib/pq"
)

// 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 (
Expand All @@ -42,15 +18,10 @@ const (

// 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
}

type ExportState struct {
CurrentRef string
State CatalogBranchExportStatus
ErrorMessage *string
CurrentRef string `db:"current_ref"`
State CatalogBranchExportStatus `db:"state"`
ErrorMessage *string `db:"error_message"`
}

// nolint: stylecheck
Expand Down
2 changes: 1 addition & 1 deletion catalog/mvcc/cataloger_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestCataloger_DiffEmpty(t *testing.T) {
}
commitChanges(10, "Changes on master", "master")

res, hasMore, err := c.Diff(ctx, repository, "master", "master", DiffParams{Limit: 10})
res, hasMore, err := c.Diff(ctx, repository, "master", "master", catalog.DiffParams{Limit: 10})
testutil.MustDo(t, "Diff", err)
if len(res) != 0 {
t.Errorf("Diff: got %+v but expected nothing", res)
Expand Down
75 changes: 4 additions & 71 deletions catalog/mvcc/cataloger_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,21 @@ import (
"fmt"
"regexp"

"github.com/georgysavva/scany/pgxscan"
"github.com/jackc/pgconn"
"github.com/lib/pq"

"github.com/georgysavva/scany/pgxscan"
"github.com/treeverse/lakefs/catalog"
"github.com/treeverse/lakefs/db"
"github.com/treeverse/lakefs/logging"
)

// 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) {
func (c *cataloger) GetExportConfigurationForBranch(repository string, branch string) (catalog.ExportConfiguration, error) {
ret, err := c.db.Transact(func(tx db.Tx) (interface{}, error) {
branchID, err := c.getBranchIDCache(tx, repository, branch)
if err != nil {
return nil, fmt.Errorf("repository %s branch %s: %w", repository, branch, err)
}
var ret ExportConfiguration
var ret catalog.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 @@ -159,7 +92,7 @@ func (c *cataloger) GetExportState(repo string, branch string) (catalog.ExportSt
return res.(catalog.ExportState), err
}

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

Expand Down
4 changes: 2 additions & 2 deletions catalog/mvcc/cataloger_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ func TestCataloger_MergeFromChildAfterMergeFromParent(t *testing.T) {

type MergeData struct {
Repo, Branch string
Result MergeResult
Result catalog.MergeResult
}

// MergeHookLogger - merge hook that will return an error if set by Err.
Expand All @@ -1198,7 +1198,7 @@ type MergeHookLogger struct {
Merges []MergeData
}

func (h *MergeHookLogger) Hook(_ context.Context, repo, branch string, result *MergeResult) error {
func (h *MergeHookLogger) Hook(_ context.Context, repo, branch string, result *catalog.MergeResult) error {
if h.Err != nil {
return h.Err
}
Expand Down
2 changes: 1 addition & 1 deletion export/export_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (h *Handler) start(body *string) error {
return h.generateTasks(startData, startData.ExportConfig, &finishBodyStr, repo.StorageNamespace)
}

func (h *Handler) generateTasks(startData StartData, config catalog.Cataloger, finishBodyStr *string, storageNamespace string) error {
func (h *Handler) generateTasks(startData StartData, config catalog.ExportConfiguration, finishBodyStr *string, storageNamespace string) error {
tasksGenerator := NewTasksGenerator(startData.ExportID, config.Path, getGenerateSuccess(config.LastKeysInPrefixRegexp), finishBodyStr, storageNamespace)
var diffs catalog.Differences
var err error
Expand Down

0 comments on commit 74527c9

Please sign in to comment.