fix(db): fix id generator errors

Former-commit-id: 898a8d587fe81717bc51aba9d5672775b819f100
pull/191/head
Xu Peng 2019-04-15 13:43:28 +08:00
parent f0a66cac52
commit 89125a9fb6
3 changed files with 21 additions and 22 deletions

View File

@ -1,32 +1,37 @@
#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

View File

@ -1,5 +1,4 @@
#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_

View File

@ -1,5 +1,4 @@
#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_