提交 28e42d0e 编写于 作者: X Xu Peng 提交者: xj.lin

fix(db): fix id generator errors


Former-commit-id: 1068933b6c74775bfc1ee8641c41d095babaea0c
上级 3863f2d3
#include <chrono>
#include <assert.h>
#inlcude "id_generators.h"
#include "id_generators.h"
using std::chrono;
namespace vecengine {
namespace zilliz {
namespace vecwise {
namespace engine {
IDGenerator::~IDGenerator() {}
IDNumber SimpleIDGenerator::getNextIDNumber() {
auto now = chrono::system_clock::now();
auto micros = duration_cast<chrono::microseconds>(now.time_since_epoch()).count();
return micros * MAX_IDS_PER_MICRO
auto now = std::chrono::system_clock::now();
auto micros = std::chrono::duration_cast<std::chrono::microseconds>(
now.time_since_epoch()).count();
return micros * MAX_IDS_PER_MICRO;
}
IDNumbers&& SimpleIDGenerator::getNextIDNumbers(size_t n) {
assert(n < MAX_IDS_PER_MICRO);
auto now = chrono::system_clock::now();
auto micros = duration_cast<chrono::microseconds>(now.time_since_epoch()).count();
auto now = std::chrono::system_clock::now();
auto micros = std::chrono::duration_cast<std::chrono::microseconds>(
now.time_since_epoch()).count();
micros *= MAX_IDS_PER_MICRO;
IDNumbers ids = IDNumbers(n);
for (int pos=0; pos<n; ++pos) {
ids[pos] = micros + pos;
}
return ids;
return std::move(ids);
}
} // namespace vecengine
} // namespace engine
} // namespace vecwise
} // namespace zilliz
#ifndef UTILS_ID_GENERATORS_H_
#define UTILS_ID_GENERATORS_H_
#pragma once
#include <vector>
#include "types.h"
......@@ -24,7 +23,7 @@ public:
virtual IDNumbers&& getNextIDNumbers(size_t n_) override;
private:
const MAX_IDS_PER_MICRO = 1000;
const size_t MAX_IDS_PER_MICRO = 1000;
}; // SimpleIDGenerator
......@@ -32,5 +31,3 @@ private:
} // namespace engine
} // namespace vecwise
} // namespace zilliz
#endif // UTILS_ID_GENERATORS_H_
#ifndef VECENGINE_TYPES_H_
#define VECENGINE_TYPES_H_
#pragma once
#include <vector>
......@@ -7,13 +6,11 @@ namespace zilliz {
namespace vecwise {
namespace engine {
#define uint64_t IDNumber;
#define IDNumber* IDNumberPtr;
#define std::vector<IDNumber> IDNumbers;
typedef uint64_t IDNumber;
typedef IDNumber* IDNumberPtr;
typedef std::vector<IDNumber> IDNumbers;
} // namespace engine
} // namespace vecwise
} // namespace zilliz
#endif // VECENGINE_TYPES_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册