o/libraries/doltcore/table/editor: Add ability to configure map editor flush interval with environment variables.

This commit is contained in:
Aaron Son
2021-02-01 07:34:30 -08:00
parent 68331035e4
commit 7570f49e42
3 changed files with 26 additions and 4 deletions

View File

@@ -18,6 +18,8 @@ import (
"context"
"fmt"
"io"
"os"
"strconv"
"sync"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
@@ -49,7 +51,17 @@ type IndexEditor struct {
flushMutex *sync.RWMutex
}
const indexEditorMaxEdits = 16384
var (
indexEditorMaxEdits uint64 = 16384
)
func init() {
if maxOpsEnv := os.Getenv("DOLT_EDIT_INDEX_BUFFER_ROWS"); maxOpsEnv != "" {
if v, err := strconv.ParseUint(maxOpsEnv, 10, 64); err == nil {
indexEditorMaxEdits = v
}
}
}
func NewIndexEditor(index schema.Index, indexData types.Map) *IndexEditor {
return &IndexEditor{

View File

@@ -243,7 +243,7 @@ func (kte *keylessTableEditor) Close() error {
func (kte *keylessTableEditor) autoFlush(ctx context.Context) error {
// work is proportional to number of deltas
// not the number of row operations
if len(kte.acc.deltas) >= tableEditorMaxOps {
if len(kte.acc.deltas) >= int(tableEditorMaxOps) {
return kte.flush(ctx)
}
return nil

View File

@@ -18,6 +18,8 @@ import (
"context"
"fmt"
"io"
"os"
"strconv"
"strings"
"sync"
@@ -32,10 +34,18 @@ import (
"github.com/dolthub/dolt/go/store/types"
)
const (
tableEditorMaxOps = 16384
var (
tableEditorMaxOps uint64 = 16384
)
func init() {
if maxOpsEnv := os.Getenv("DOLT_EDIT_TABLE_BUFFER_ROWS"); maxOpsEnv != "" {
if v, err := strconv.ParseUint(maxOpsEnv, 10, 64); err == nil {
tableEditorMaxOps = v
}
}
}
type TableEditor interface {
InsertRow(ctx context.Context, r row.Row) error
UpdateRow(ctx context.Context, old, new row.Row) error