Skip to content

Commit

Permalink
TSDB delete by range (#377)
Browse files Browse the repository at this point in the history
* enhance TSDB delete

* update tsdb to point to talIguaz - temp

* update v3io-go + v3io-tsdb

* python linter

* update TSDB version
  • Loading branch information
talIguaz authored Feb 19, 2020
1 parent 9a02744 commit 25acdc1
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 169 deletions.
3 changes: 2 additions & 1 deletion backends/kv/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func (b *Backend) updateItem(request *frames.ExecRequest) error {
}

b.logger.DebugWith("update item", "path", path, "key", key, "expr", expr, "condition", condition)
return container.UpdateItemSync(&v3io.UpdateItemInput{Path: path + key, Expression: &expr, Condition: condition})
_, err = container.UpdateItemSync(&v3io.UpdateItemInput{Path: path + key, Expression: &expr, Condition: condition})
return err
}

/*func (b *Backend) newContainer(session *frames.Session) (v3io.Container, error) {
Expand Down
16 changes: 8 additions & 8 deletions backends/tsdb/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ import (
"time"
"unsafe"

"github.com/v3io/frames"
"github.com/v3io/frames/backends"

"github.com/golang/groupcache/lru"
"github.com/nuclio/logger"
"github.com/pkg/errors"
"github.com/v3io/frames"
"github.com/v3io/frames/backends"
"github.com/v3io/frames/v3ioutils"
v3io "github.com/v3io/v3io-go/pkg/dataplane"
"github.com/v3io/v3io-tsdb/pkg/config"
Expand Down Expand Up @@ -264,11 +263,12 @@ func (b *Backend) Delete(request *frames.DeleteRequest) error {
}
}

err = adapter.DeleteDB(delAll, false, start, end)
if err == nil {
return err
}

params := tsdb.DeleteParams{DeleteAll: delAll,
From: start,
To: end,
Filter: request.Proto.Filter,
Metrics: request.Proto.Metrics}
err = adapter.DeleteDB(params)
return err

}
Expand Down
10 changes: 7 additions & 3 deletions clients/py/v3io_frames/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pandas as pd
from os import environ

import pandas as pd

from . import frames_pb2 as fpb
from .errors import (CreateError, DeleteError, ExecuteError, ReadError,
WriteError)
Expand Down Expand Up @@ -177,7 +178,7 @@ def create(self, backend, table, attrs=None, schema=None, if_exists=FAIL):
return self._create(backend, table, attrs, schema, if_exists)

def delete(self, backend, table, filter='', start='', end='',
if_missing=FAIL):
if_missing=FAIL, metrics=[]):
"""Deletes a table or stream or specific table items
Parameters
Expand All @@ -202,14 +203,17 @@ def delete(self, backend, table, filter='', start='', end='',
days), or 0 for the earliest time; the default is "now"
if_missing : int
One of IGNORE or FAIL
metrics : string
(`tsdb` backend only) List of specific metric names to delete.
Raises
------
DeleteError
On request error or backend error
"""
self._validate_request(backend, table, DeleteError)
return self._delete(backend, table, filter, start, end, if_missing)
return self._delete(backend, table, filter, start, end,
if_missing, metrics)

def execute(self, backend, table, command='', args=None, expression=''):
"""Executes a backend-specific command on a table or stream
Expand Down
39 changes: 23 additions & 16 deletions clients/py/v3io_frames/frames_pb2.py

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

3 changes: 2 additions & 1 deletion clients/py/v3io_frames/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _create(self, backend, table, attrs, schema, if_exists):
stub.Create(request)

@grpc_raise(DeleteError)
def _delete(self, backend, table, filter, start, end, if_missing):
def _delete(self, backend, table, filter, start, end, if_missing, metrics):
start, end = time2str(start), time2str(end)
stub = fgrpc.FramesStub(self._channel)
request = fpb.DeleteRequest(
Expand All @@ -161,6 +161,7 @@ def _delete(self, backend, table, filter, start, end, if_missing):
start=start,
end=end,
if_missing=if_missing,
metrics=metrics,
)
stub.Delete(request)

Expand Down
6 changes: 4 additions & 2 deletions clients/py/v3io_frames/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# limitations under the License.

import json
import requests
import struct
from base64 import b64decode
from datetime import datetime
from functools import partial, wraps
from itertools import chain

import requests
from requests.exceptions import RequestException
from urllib3.exceptions import HTTPError

Expand Down Expand Up @@ -146,7 +147,7 @@ def _create(self, backend, table, attrs, schema, if_exists):
raise CreateError(resp.text)

@connection_error(DeleteError)
def _delete(self, backend, table, filter, start, end, if_missing):
def _delete(self, backend, table, filter, start, end, if_missing, metrics):
request = {
'session': pb2py(self.session),
'backend': backend,
Expand All @@ -155,6 +156,7 @@ def _delete(self, backend, table, filter, start, end, if_missing):
'start': start,
'end': end,
'if_missing': if_missing,
'metrics': metrics,
}

convert_go_times(request, ('start', 'end'))
Expand Down
1 change: 1 addition & 0 deletions frames.proto
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ message DeleteRequest {
// TSDB and Stream specific fields
string start = 6;
string end = 7;
repeated string metrics = 8;
}

message DeleteResponse {}
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ require (
github.com/nuclio/errors v0.0.1
github.com/nuclio/logger v0.0.1
github.com/nuclio/zap v0.0.2
github.com/philhofer/fwd v1.0.0 // indirect
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.4.0
github.com/v3io/v3io-go v0.0.5-0.20191205125653-9003ae83f0b6
github.com/v3io/v3io-tsdb v0.9.12-4
github.com/v3io/v3io-go v0.0.7-0.20200216132233-3b52a325296d
github.com/v3io/v3io-tsdb v0.9.12-5
github.com/valyala/fasthttp v1.2.0
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
Expand Down
Loading

0 comments on commit 25acdc1

Please sign in to comment.