diff --git a/core/src/dog_segment/CMakeLists.txt b/core/src/dog_segment/CMakeLists.txt index 2805582b6e..41b0f4be21 100644 --- a/core/src/dog_segment/CMakeLists.txt +++ b/core/src/dog_segment/CMakeLists.txt @@ -1,6 +1,9 @@ set(DOG_SEGMENT_FILES SegmentNaive.cpp Collection.cpp + Partition.cpp + collection_c.cpp + partition_c.cpp segment_c.cpp ) # Third Party dablooms file diff --git a/core/src/dog_segment/Collection.cpp b/core/src/dog_segment/Collection.cpp index 0373659df1..b45b82d60d 100644 --- a/core/src/dog_segment/Collection.cpp +++ b/core/src/dog_segment/Collection.cpp @@ -1,2 +1,17 @@ #include "Collection.h" +namespace milvus::dog_segment { + +Collection::Collection(std::string &collection_name, std::string &schema): + collection_name_(collection_name), schema_json_(schema){} + +void +Collection::set_index() {} + +void +Collection::parse() {} + +void +Collection::AddNewPartition() {} + +} diff --git a/core/src/dog_segment/Collection.h b/core/src/dog_segment/Collection.h index 44cf7e8f4b..2ad0b47634 100644 --- a/core/src/dog_segment/Collection.h +++ b/core/src/dog_segment/Collection.h @@ -1,52 +1,21 @@ #pragma once +#include "dog_segment/Partition.h" #include "SegmentDefs.h" -#include "SegmentBase.h" - -////////////////////////////////////////////////////////////////// namespace milvus::dog_segment { -class Partition { -public: - explicit Partition(std::string& partition_name): partition_name_(partition_name) {} - - const std::vector &segments() const { - return segments_; - } - -private: - std::string partition_name_; - std::vector segments_; -}; - -using PartitionPtr = std::shared_ptr; - -////////////////////////////////////////////////////////////////// - class Collection { public: - explicit Collection(std::string &collection_name, std::string &schema) - : collection_name_(collection_name), schema_json_(schema) {} + explicit Collection(std::string &collection_name, std::string &schema); // TODO: set index - void set_index() {} + void set_index(); - void parse() { - // TODO: config to schema - } + // TODO: config to schema + void parse(); -public: - -// std::vector Insert() { -// for (auto partition: partitions_) { -// for (auto segment: partition.segments()) { -// if (segment.Status == Status.open) { -// segment.Insert() -// } -// } -// } -// } + void AddNewPartition(); private: // TODO: add Index ptr diff --git a/core/src/dog_segment/Partition.cpp b/core/src/dog_segment/Partition.cpp new file mode 100644 index 0000000000..cd31a5ca50 --- /dev/null +++ b/core/src/dog_segment/Partition.cpp @@ -0,0 +1,20 @@ +#include "Partition.h" + +namespace milvus::dog_segment { + +Partition::Partition(std::string& partition_name): + partition_name_(partition_name) {} + +void +Partition::AddNewSegment(uint64_t segment_id) { + auto segment = CreateSegment(); + segment->set_segment_id(segment_id); + segments_.emplace_back(segment); +} + +Partition* +CreatePartition() { + +} + +} diff --git a/core/src/dog_segment/Partition.h b/core/src/dog_segment/Partition.h new file mode 100644 index 0000000000..bea4f26276 --- /dev/null +++ b/core/src/dog_segment/Partition.h @@ -0,0 +1,26 @@ +#pragma once + +#include "SegmentBase.h" + +namespace milvus::dog_segment { + +class Partition { +public: + explicit Partition(std::string& partition_name); + + const std::vector &segments() const { + return segments_; + } + + void AddNewSegment(uint64_t segment_id); + +private: + std::string partition_name_; + std::vector segments_; +}; + +using PartitionPtr = std::shared_ptr; + +Partition* CreatePartiton(); + +} \ No newline at end of file diff --git a/core/src/dog_segment/collection_c.cpp b/core/src/dog_segment/collection_c.cpp index e69de29bb2..4ba3fc5618 100644 --- a/core/src/dog_segment/collection_c.cpp +++ b/core/src/dog_segment/collection_c.cpp @@ -0,0 +1,11 @@ +#include "collection_c.h" + +CCollection +NewCollection(const char* collection_name) { + +} + +void +DeleteCollection(CCollection collection) { + +} diff --git a/core/src/dog_segment/collection_c.h b/core/src/dog_segment/collection_c.h index e69de29bb2..fd4a96f118 100644 --- a/core/src/dog_segment/collection_c.h +++ b/core/src/dog_segment/collection_c.h @@ -0,0 +1,13 @@ +#ifdef __cplusplus +extern "C" { +#endif + +typedef void* CCollection; + +CCollection NewCollection(const char* collection_name); + +void DeleteCollection(CCollection collection); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/core/src/dog_segment/partition_c.cpp b/core/src/dog_segment/partition_c.cpp new file mode 100644 index 0000000000..a40b4e30eb --- /dev/null +++ b/core/src/dog_segment/partition_c.cpp @@ -0,0 +1,12 @@ +#include "partition_c.h" +#include "Partition.h" +#include "Collection.h" + +CPartition +NewPartition(CCollection collection, const char* partition_name) { + auto name = std::string(partition_name); + auto partition = new milvus::dog_segment::Partition(name); + + auto co = (milvus::dog_segment::Collection*)collection; + co->AddNewPartition(); +} diff --git a/core/src/dog_segment/partition_c.h b/core/src/dog_segment/partition_c.h new file mode 100644 index 0000000000..96e86cac72 --- /dev/null +++ b/core/src/dog_segment/partition_c.h @@ -0,0 +1,15 @@ +#ifdef __cplusplus +extern "C" { +#endif + +#include "collection_c.h" + +typedef void* CPartition; + +CPartition NewPartition(CCollection collection, const char* partition_name); + +void DeletePartition(CPartition partition); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/reader/query_node.go b/reader/query_node.go index 5b985dd78e..dc6a8b2265 100644 --- a/reader/query_node.go +++ b/reader/query_node.go @@ -119,7 +119,8 @@ func (node *QueryNode) InitQueryNodeCollection() { node.Collections = append(node.Collections, collection) var partition, _ = collection.NewPartition("partition1") collection.Partitions = append(collection.Partitions, partition) - var segment, _ = partition.NewSegment() + // TODO: add segment id + var segment, _ = partition.NewSegment(0) partition.Segments = append(partition.Segments, segment) } @@ -128,10 +129,11 @@ func (node *QueryNode) SegmentsManagement() { for _, collection := range node.Collections { for _, partition := range collection.Partitions { for _, segment := range partition.Segments { + // TODO: check segment status if timeSync >= segment.SegmentCloseTime { segment.Close() // TODO: add atomic segment id - var newSegment, _ = partition.NewSegment() + var newSegment, _ = partition.NewSegment(0) newSegment.SegmentCloseTime = timeSync + SegmentLifetime partition.Segments = append(partition.Segments, newSegment) } diff --git a/reader/segment.go b/reader/segment.go index 66ffc9e877..45dcd6cceb 100644 --- a/reader/segment.go +++ b/reader/segment.go @@ -1,5 +1,14 @@ package reader +/* + +#cgo CFLAGS: -I../core/include + +#cgo LDFLAGS: -L../core/lib -lmilvus_dog_segment -Wl,-rpath=../core/lib + +#include "segment_c.h" + +*/ import "C" import ( "errors" @@ -14,9 +23,9 @@ type Segment struct { SegmentCloseTime uint64 } -func (p *Partition) NewSegment() (*Segment, error) { +func (p *Partition) NewSegment(segmentId uint64) (*Segment, error) { // TODO: add segment id - segmentPtr, status := C.CreateSegment(p.PartitionPtr) + segmentPtr, status := C.SegmentBaseInit(p.PartitionPtr) if status != 0 { return nil, errors.New("create segment failed") diff --git a/reader/test/cgo_segment_test.go b/reader/test/cgo_segment_test.go new file mode 100644 index 0000000000..a81b934389 --- /dev/null +++ b/reader/test/cgo_segment_test.go @@ -0,0 +1,10 @@ +package main + +import ( + "fmt" + "testing" +) + +func TestIntMinBasic(t *testing.T) { + fmt.Println("Hello go testing") +} \ No newline at end of file