add checks for data presence on import req

This commit is contained in:
Samir Patel 2021-11-01 17:04:33 -05:00
parent e769c085ae
commit 002b65c516
2 changed files with 10 additions and 1 deletions

7
api.go
View file

@ -1760,6 +1760,9 @@ func (api *API) ImportValueWithTx(ctx context.Context, qcx *Qcx, req *ImportValu
// if we're importing into a specific shard
if req.Shard != math.MaxUint64 {
if len(req.ColumnIDs) == 0 {
return errors.Wrap(err, "calculating shard, no columns in request")
}
// Check that column IDs match the stated shard.
shard := req.ColumnIDs[0] / ShardWidth
if s2 := req.ColumnIDs[len(req.ColumnIDs)-1] / ShardWidth; (shard != s2) || (shard != req.Shard) {
@ -1798,7 +1801,9 @@ func (api *API) ImportValueWithTx(ctx context.Context, qcx *Qcx, req *ImportValu
return errors.Wrap(err, "importing value")
} // end if req.Shard != math.MaxUint64
if len(req.ColumnIDs) == 0 {
return errors.Wrap(err, "calculating shard, no columns in request")
}
options.IgnoreKeyCheck = true
start := 0
shard := req.ColumnIDs[0] / ShardWidth

View file

@ -2721,6 +2721,10 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
qcx := h.api.Txf().NewQcx()
defer qcx.Abort()
if len(req.Values) == 0 {
return
}
if err := h.api.ImportValue(r.Context(), qcx, req, opts...); err != nil {
switch errors.Cause(err) {
case pilosa.ErrClusterDoesNotOwnShard, pilosa.ErrPreconditionFailed: