File size: 2,319 Bytes
b110593
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//                           _       _
// __      _____  __ ___   ___  __ _| |_ ___
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
//  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
//   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
//
//  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
//
//  CONTACT: [email protected]
//

package main

// build with:  go build -buildmode c-shared -o libweaviate.so .

// The function signature must not include neither Go struct nor Go interface nor Go array nor variadic argument.

import (
	"C"
	"context"
	"fmt"
	"os"

	"github.com/sirupsen/logrus"
	"github.com/weaviate/weaviate/adapters/handlers/rest"
	"github.com/weaviate/weaviate/adapters/repos/db/helpers"
	"github.com/weaviate/weaviate/adapters/repos/db/lsmkv"
	"github.com/weaviate/weaviate/entities/cyclemanager"
	"github.com/weaviate/weaviate/usecases/config"
)

var started = false

//export dumpBucket
func dumpBucket(storeDir, propName string) {
	if !started {
		fmt.Println("Weaviate has not been started!  Call startWeaviate() before any other function")
		os.Exit(1)
	}

	kvstore, err := lsmkv.New(storeDir, storeDir, &logrus.Logger{}, nil, cyclemanager.NewCallbackGroupNoop(), cyclemanager.NewCallbackGroupNoop())
	if err != nil {
		panic(err)
	}

	fmt.Printf("propName: %s\n", propName)
	bucketName := helpers.BucketFromPropNameLSM(propName)
	fmt.Printf("bucketName: %s\n", bucketName)
	err = kvstore.CreateOrLoadBucket(context.Background(), bucketName, lsmkv.WithStrategy(lsmkv.StrategyMapCollection))
	if err != nil {
		panic(err)
	}

	bucket := kvstore.Bucket(bucketName)
	fmt.Printf("Dir: %v, bucket %v\n", storeDir, bucketName)
	bucket.IterateMapObjects(context.Background(), func(k1, k2, v []byte, tombstone bool) error {
		fmt.Printf("k1: %s\n", k1)
		fmt.Printf("k2: %x\n", k2)
		fmt.Printf("v: %x\n", v)
		fmt.Printf("tombstone: %v\n", tombstone)
		fmt.Println("-----")
		return nil
	})
	fmt.Printf("Dir: %v, bucket %v\n", storeDir, bucketName)
}

//export startWeaviate
func startWeaviate() {
	config := config.GetConfigOptionGroup()
	rest.MakeAppState(context.Background(), config)
	if len(os.Args) != 3 {
		fmt.Printf("Usage: %s <storeDir> <propName>\n", os.Args[0])
		os.Exit(1)
	}
	started = true
}

func main() {
}