mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-30 10:59:32 +08:00
Refactor collection and partition
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
parent
26805ebd3a
commit
b6cc1df97e
@ -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
|
||||
|
@ -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() {}
|
||||
|
||||
}
|
||||
|
@ -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<SegmentBasePtr> &segments() const {
|
||||
return segments_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string partition_name_;
|
||||
std::vector<SegmentBasePtr> segments_;
|
||||
};
|
||||
|
||||
using PartitionPtr = std::shared_ptr<Partition>;
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
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<int64_t> Insert() {
|
||||
// for (auto partition: partitions_) {
|
||||
// for (auto segment: partition.segments()) {
|
||||
// if (segment.Status == Status.open) {
|
||||
// segment.Insert()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
void AddNewPartition();
|
||||
|
||||
private:
|
||||
// TODO: add Index ptr
|
||||
|
20
core/src/dog_segment/Partition.cpp
Normal file
20
core/src/dog_segment/Partition.cpp
Normal file
@ -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() {
|
||||
|
||||
}
|
||||
|
||||
}
|
26
core/src/dog_segment/Partition.h
Normal file
26
core/src/dog_segment/Partition.h
Normal file
@ -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<SegmentBasePtr> &segments() const {
|
||||
return segments_;
|
||||
}
|
||||
|
||||
void AddNewSegment(uint64_t segment_id);
|
||||
|
||||
private:
|
||||
std::string partition_name_;
|
||||
std::vector<SegmentBasePtr> segments_;
|
||||
};
|
||||
|
||||
using PartitionPtr = std::shared_ptr<Partition>;
|
||||
|
||||
Partition* CreatePartiton();
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
#include "collection_c.h"
|
||||
|
||||
CCollection
|
||||
NewCollection(const char* collection_name) {
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
DeleteCollection(CCollection collection) {
|
||||
|
||||
}
|
@ -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
|
12
core/src/dog_segment/partition_c.cpp
Normal file
12
core/src/dog_segment/partition_c.cpp
Normal file
@ -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();
|
||||
}
|
15
core/src/dog_segment/partition_c.h
Normal file
15
core/src/dog_segment/partition_c.h
Normal file
@ -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
|
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
|
10
reader/test/cgo_segment_test.go
Normal file
10
reader/test/cgo_segment_test.go
Normal file
@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIntMinBasic(t *testing.T) {
|
||||
fmt.Println("Hello go testing")
|
||||
}
|
Loading…
Reference in New Issue
Block a user