Skip to content

Commit

Permalink
Add support for configuring 'cache' and 'cache_ttl' per instance. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
binaek authored Mar 29, 2023
1 parent 071e190 commit cb0cada
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 110 deletions.
46 changes: 39 additions & 7 deletions fdw.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,20 +447,52 @@ func handleCommandInsert(rinfo *C.ResultRelInfo, slot *C.TupleTableSlot, rel C.R
opts := GetFTableOptions(types.Oid(relid))

switch opts["table"] {
case constants.CommandTableCache:
// we know there is just a single column - operation
var isNull C.bool
datum := C.slot_getattr(slot, 1, &isNull)
operation := C.GoString(C.fdw_datumGetString(datum))
case constants.CommandTableSettings:
tupleDesc := buildTupleDesc(rel.rd_att)
attributes := tupleDesc.Attrs
hub, err := hub.GetHub()
if err != nil {
FdwError(err)
return nil
}
if err := hub.HandleCacheCommand(operation); err != nil {
FdwError(err)
var key *string
var value *string

// iterate through the attributes
for i, a := range attributes {
var isNull C.bool
datum := C.slot_getattr(slot, C.int(i+1), &isNull)
if isNull {
continue
}
// get a string from the memory slot
datumStr := C.GoString(C.fdw_datumGetString(datum))

log.Println("[TRACE] name", a.Name)
log.Println("[TRACE] datum", datum)
log.Println("[TRACE] datumstr", datumStr)

// map it to one of key/value
switch a.Name {
case constants.CommandTableSettingsKeyColumn:
key = &datumStr
case constants.CommandTableSettingsValueColumn:
value = &datumStr
}
}

// if both key and value are not set, ERROR
if key == nil || value == nil {
FdwError(fmt.Errorf("invalid setting: both 'key' and 'value' columns need to be set"))
return nil
}

// apply the setting
if err = hub.ApplySetting(*key, *value); err != nil {
FdwError(err)
}
return nil

}

return nil
Expand Down
42 changes: 25 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/turbot/go-kit v0.5.0
github.com/turbot/steampipe v0.19.0-rc.10
github.com/turbot/steampipe-plugin-sdk/v5 v5.2.1-alpha.0
github.com/turbot/steampipe-plugin-sdk/v5 v5.3.0-rc.0
go.opentelemetry.io/otel v1.10.0
google.golang.org/protobuf v1.28.1
google.golang.org/protobuf v1.29.1
)

require (
Expand All @@ -27,15 +27,22 @@ require (
cloud.google.com/go/storage v1.27.0 // indirect
github.com/aws/aws-sdk-go v1.44.183 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/briandowns/spinner v1.23.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/hashicorp/go-getter v1.6.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/jackc/pgx/v5 v5.3.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jackc/puddle/v2 v2.2.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/karrick/gows v0.3.0 // indirect
github.com/klauspost/compress v1.11.2 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.107.0 // indirect
)
Expand Down Expand Up @@ -65,7 +72,7 @@ require (
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/eko/gocache/v3 v3.1.2 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gertd/go-pluralize v0.2.1
Expand All @@ -83,11 +90,11 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.8 // indirect
github.com/hashicorp/go-plugin v1.4.9 // indirect
github.com/hashicorp/go-retryablehttp v0.5.2 // indirect
github.com/hashicorp/go-uuid v1.0.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.16.1 // indirect
github.com/hashicorp/hcl/v2 v2.16.2 // indirect
github.com/hashicorp/terraform v0.15.1 // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
Expand All @@ -101,7 +108,7 @@ require (
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
Expand Down Expand Up @@ -131,16 +138,14 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/stevenle/topsort v0.0.0-20130922064739-8130c1d7596b // indirect
github.com/stevenle/topsort v0.2.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
github.com/tkrajina/go-reflector v0.5.6 // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
github.com/zclconf/go-cty v1.12.1 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
github.com/zclconf/go-cty-yaml v1.0.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.7.0 // indirect
Expand All @@ -154,15 +159,15 @@ require (
go.opentelemetry.io/proto/otlp v0.16.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/exp v0.0.0-20221110155412-d0897a79cd37 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/grpc v1.54.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
Expand All @@ -176,4 +181,7 @@ replace (
github.com/deislabs/oras => github.com/oras-project/oras v0.9.0
github.com/docker/distribution => github.com/distribution/distribution v2.7.1+incompatible
github.com/docker/docker => github.com/moby/moby v20.10.17+incompatible

// 3258-updates-in-caching-behaviour
github.com/turbot/steampipe => github.com/turbot/steampipe v1.7.0-rc.0.0.20230327152311-88e87507e979
)
Loading

0 comments on commit cb0cada

Please sign in to comment.