@@ -13,27 +13,41 @@ import (
13
13
"unsafe"
14
14
)
15
15
16
+ type consolidationPlanHandle struct { * capiHandle }
17
+
18
+ func freeCapiConsolidationPlan (c unsafe.Pointer ) {
19
+ C .tiledb_consolidation_plan_free ((* * C .tiledb_consolidation_plan_t )(unsafe .Pointer (& c )))
20
+ }
21
+
22
+ func newConsolidationPlanHandle (ptr * C.tiledb_consolidation_plan_t ) consolidationPlanHandle {
23
+ return consolidationPlanHandle {newCapiHandle (unsafe .Pointer (ptr ), freeCapiConsolidationPlan )}
24
+ }
25
+
26
+ func (x consolidationPlanHandle ) Get () * C.tiledb_consolidation_plan_t {
27
+ return (* C .tiledb_consolidation_plan_t )(x .capiHandle .Get ())
28
+ }
29
+
16
30
// ConsolidationPlan is a consolidation plan for array
17
31
type ConsolidationPlan struct {
18
- tiledbConsolidationPlan * C. tiledb_consolidation_plan_t
32
+ tiledbConsolidationPlan consolidationPlanHandle
19
33
context * Context
20
34
}
21
35
36
+ func newConsolidationPlanFromHandle (context * Context , handle consolidationPlanHandle ) * ConsolidationPlan {
37
+ return & ConsolidationPlan {tiledbConsolidationPlan : handle , context : context }
38
+ }
39
+
22
40
// GetConsolidationPlan creates a consolidation plan for the already opened array.
23
41
// The plan and the array will share the same tiledb context
24
42
func GetConsolidationPlan (arr * Array , fragmentSize uint64 ) (* ConsolidationPlan , error ) {
25
- cp := & ConsolidationPlan {
26
- context : arr .context ,
27
- }
28
-
29
- ret := C .tiledb_consolidation_plan_create_with_mbr (cp .context .tiledbContext , arr .tiledbArray , C .uint64_t (fragmentSize ), & cp .tiledbConsolidationPlan )
43
+ var consolidationPlanPtr * C.tiledb_consolidation_plan_t
44
+ ret := C .tiledb_consolidation_plan_create_with_mbr (arr .context .tiledbContext .Get (), arr .tiledbArray .Get (), C .uint64_t (fragmentSize ), & consolidationPlanPtr )
30
45
runtime .KeepAlive (arr )
31
46
if ret != C .TILEDB_OK {
32
- return nil , fmt .Errorf ("error getting consolidation plan for array: %w" , cp .context .LastError ())
47
+ return nil , fmt .Errorf ("error getting consolidation plan for array: %w" , arr .context .LastError ())
33
48
}
34
- freeOnGC (cp )
35
49
36
- return cp , nil
50
+ return newConsolidationPlanFromHandle ( arr . context , newConsolidationPlanHandle ( consolidationPlanPtr )) , nil
37
51
}
38
52
39
53
// Free releases the internal TileDB core data that was allocated on the C heap.
@@ -42,16 +56,14 @@ func GetConsolidationPlan(arr *Array, fragmentSize uint64) (*ConsolidationPlan,
42
56
// can safely be called many times on the same object; if it has already
43
57
// been freed, it will not be freed again.
44
58
func (cp * ConsolidationPlan ) Free () {
45
- if cp .tiledbConsolidationPlan != nil {
46
- C .tiledb_consolidation_plan_free (& cp .tiledbConsolidationPlan )
47
- }
59
+ cp .tiledbConsolidationPlan .Free ()
48
60
}
49
61
50
62
// NumNodes returns the number of nodes for the plan
51
63
func (cp * ConsolidationPlan ) NumNodes () (uint64 , error ) {
52
64
var numNodes C.uint64_t
53
65
54
- ret := C .tiledb_consolidation_plan_get_num_nodes (cp .context .tiledbContext , cp .tiledbConsolidationPlan , & numNodes )
66
+ ret := C .tiledb_consolidation_plan_get_num_nodes (cp .context .tiledbContext . Get () , cp .tiledbConsolidationPlan . Get () , & numNodes )
55
67
runtime .KeepAlive (cp )
56
68
if ret != C .TILEDB_OK {
57
69
return 0 , fmt .Errorf ("error getting consolidation plan num nodes: %w" , cp .context .LastError ())
@@ -64,7 +76,7 @@ func (cp *ConsolidationPlan) NumNodes() (uint64, error) {
64
76
func (cp * ConsolidationPlan ) NumFragments (nodeIndex uint64 ) (uint64 , error ) {
65
77
var numFragments C.uint64_t
66
78
67
- ret := C .tiledb_consolidation_plan_get_num_fragments (cp .context .tiledbContext , cp .tiledbConsolidationPlan , C .uint64_t (nodeIndex ), & numFragments )
79
+ ret := C .tiledb_consolidation_plan_get_num_fragments (cp .context .tiledbContext . Get () , cp .tiledbConsolidationPlan . Get () , C .uint64_t (nodeIndex ), & numFragments )
68
80
runtime .KeepAlive (cp )
69
81
if ret != C .TILEDB_OK {
70
82
return 0 , fmt .Errorf ("error getting consolidation plan num fragments: %w" , cp .context .LastError ())
@@ -77,7 +89,7 @@ func (cp *ConsolidationPlan) NumFragments(nodeIndex uint64) (uint64, error) {
77
89
func (cp * ConsolidationPlan ) FragmentURI (nodeIndex , fragmentIndex uint64 ) (string , error ) {
78
90
var curi * C.char
79
91
80
- ret := C .tiledb_consolidation_plan_get_fragment_uri (cp .context .tiledbContext , cp .tiledbConsolidationPlan , C .uint64_t (nodeIndex ), C .uint64_t (fragmentIndex ), & curi )
92
+ ret := C .tiledb_consolidation_plan_get_fragment_uri (cp .context .tiledbContext . Get () , cp .tiledbConsolidationPlan . Get () , C .uint64_t (nodeIndex ), C .uint64_t (fragmentIndex ), & curi )
81
93
runtime .KeepAlive (cp )
82
94
if ret != C .TILEDB_OK {
83
95
return "" , fmt .Errorf ("error getting consolidation plan fragment uri for node %d and fragment %d: %w" , nodeIndex , fragmentIndex , cp .context .LastError ())
@@ -89,7 +101,7 @@ func (cp *ConsolidationPlan) FragmentURI(nodeIndex, fragmentIndex uint64) (strin
89
101
// DumpJSON returns a json serialization of the plan
90
102
func (cp * ConsolidationPlan ) DumpJSON () (string , error ) {
91
103
var cjson * C.char
92
- ret := C .tiledb_consolidation_plan_dump_json_str (cp .context .tiledbContext , cp .tiledbConsolidationPlan , & cjson )
104
+ ret := C .tiledb_consolidation_plan_dump_json_str (cp .context .tiledbContext . Get () , cp .tiledbConsolidationPlan . Get () , & cjson )
93
105
runtime .KeepAlive (cp )
94
106
if ret != C .TILEDB_OK {
95
107
return "" , fmt .Errorf ("error getting consolidation plan json dump: %w" , cp .context .LastError ())
@@ -119,7 +131,7 @@ func (a *Array) ConsolidateFragments(config *Config, fragmentList []string) erro
119
131
list , freeMemory := cStringArray (fragmentList )
120
132
defer freeMemory ()
121
133
122
- ret := C .tiledb_array_consolidate_fragments (a .context .tiledbContext , curi , (* * C .char )(slicePtr (list )), C .uint64_t (len (list )), config .tiledbConfig )
134
+ ret := C .tiledb_array_consolidate_fragments (a .context .tiledbContext . Get () , curi , (* * C .char )(slicePtr (list )), C .uint64_t (len (list )), config .tiledbConfig . Get () )
123
135
runtime .KeepAlive (a )
124
136
if ret != C .TILEDB_OK {
125
137
return fmt .Errorf ("error consolidating tiledb array fragment list: %w" , a .context .LastError ())
0 commit comments