mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Revert lmdb-store upgrade (#83830)
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
e45b76c1b2
commit
45d3861219
3 changed files with 65 additions and 48 deletions
|
@ -723,7 +723,7 @@
|
|||
"less": "npm:@elastic/less@2.7.3-kibana",
|
||||
"license-checker": "^16.0.0",
|
||||
"listr": "^0.14.1",
|
||||
"lmdb-store": "^0.8.15",
|
||||
"lmdb-store": "^0.6.10",
|
||||
"load-grunt-config": "^3.0.1",
|
||||
"loader-utils": "^1.2.3",
|
||||
"log-symbols": "^2.2.0",
|
||||
|
|
|
@ -18,11 +18,20 @@
|
|||
*/
|
||||
|
||||
import Path from 'path';
|
||||
import Fs from 'fs';
|
||||
|
||||
// @ts-expect-error no types available
|
||||
import * as LmdbStore from 'lmdb-store';
|
||||
import { REPO_ROOT, UPSTREAM_BRANCH } from '@kbn/dev-utils';
|
||||
|
||||
const CACHE_DIR = Path.resolve(REPO_ROOT, 'data/node_auto_transpilation_cache', UPSTREAM_BRANCH);
|
||||
const LMDB_PKG = JSON.parse(
|
||||
Fs.readFileSync(Path.resolve(REPO_ROOT, 'node_modules/lmdb-store/package.json'), 'utf8')
|
||||
);
|
||||
const CACHE_DIR = Path.resolve(
|
||||
REPO_ROOT,
|
||||
`data/node_auto_transpilation_cache/lmdb-${LMDB_PKG.version}/${UPSTREAM_BRANCH}`
|
||||
);
|
||||
|
||||
const reportError = () => {
|
||||
// right now I'm not sure we need to worry about errors, the cache isn't actually
|
||||
// necessary, and if the cache is broken it should just rebuild on the next restart
|
||||
|
@ -36,11 +45,30 @@ const MINUTE = 1000 * 60;
|
|||
const HOUR = MINUTE * 60;
|
||||
const DAY = HOUR * 24;
|
||||
|
||||
interface Lmdb<T> {
|
||||
name: string;
|
||||
get(key: string): T | undefined;
|
||||
put(key: string, value: T, version?: number, ifVersion?: number): Promise<boolean>;
|
||||
remove(key: string, ifVersion?: number): Promise<boolean>;
|
||||
removeSync(key: string): void;
|
||||
openDB<T2>(options: {
|
||||
name: string;
|
||||
encoding: 'msgpack' | 'string' | 'json' | 'binary';
|
||||
}): Lmdb<T2>;
|
||||
getRange(options?: {
|
||||
start?: T;
|
||||
end?: T;
|
||||
reverse?: boolean;
|
||||
limit?: number;
|
||||
versions?: boolean;
|
||||
}): Iterable<{ key: string; value: T }>;
|
||||
}
|
||||
|
||||
export class Cache {
|
||||
private readonly codes: LmdbStore.RootDatabase;
|
||||
private readonly atimes: LmdbStore.Database;
|
||||
private readonly mtimes: LmdbStore.Database;
|
||||
private readonly sourceMaps: LmdbStore.Database;
|
||||
private readonly codes: Lmdb<string>;
|
||||
private readonly atimes: Lmdb<string>;
|
||||
private readonly mtimes: Lmdb<string>;
|
||||
private readonly sourceMaps: Lmdb<any>;
|
||||
private readonly prefix: string;
|
||||
|
||||
constructor(config: { prefix: string }) {
|
||||
|
@ -77,7 +105,7 @@ export class Cache {
|
|||
}
|
||||
|
||||
getMtime(path: string) {
|
||||
return this.safeGet<string>(this.mtimes, this.getKey(path));
|
||||
return this.safeGet(this.mtimes, this.getKey(path));
|
||||
}
|
||||
|
||||
getCode(path: string) {
|
||||
|
@ -88,11 +116,11 @@ export class Cache {
|
|||
// touched in a long time (currently 30 days)
|
||||
this.atimes.put(key, GLOBAL_ATIME).catch(reportError);
|
||||
|
||||
return this.safeGet<string>(this.codes, key);
|
||||
return this.safeGet(this.codes, key);
|
||||
}
|
||||
|
||||
getSourceMap(path: string) {
|
||||
return this.safeGet<any>(this.sourceMaps, this.getKey(path));
|
||||
return this.safeGet(this.sourceMaps, this.getKey(path));
|
||||
}
|
||||
|
||||
update(path: string, file: { mtime: string; code: string; map: any }) {
|
||||
|
@ -110,11 +138,13 @@ export class Cache {
|
|||
return `${this.prefix}${path}`;
|
||||
}
|
||||
|
||||
private safeGet<V>(db: LmdbStore.Database, key: string) {
|
||||
private safeGet<V>(db: Lmdb<V>, key: string) {
|
||||
try {
|
||||
return db.get(key) as V | undefined;
|
||||
return db.get(key);
|
||||
} catch (error) {
|
||||
// get errors indicate that a key value is corrupt in some way, so remove it
|
||||
process.stderr.write(
|
||||
`failed to read node transpilation [${db.name}] cache for [${key}]: ${error.stack}\n`
|
||||
);
|
||||
db.removeSync(key);
|
||||
}
|
||||
}
|
||||
|
@ -124,13 +154,12 @@ export class Cache {
|
|||
const ATIME_LIMIT = Date.now() - 30 * DAY;
|
||||
const BATCH_SIZE = 1000;
|
||||
|
||||
const validKeys: LmdbStore.Key[] = [];
|
||||
const invalidKeys: LmdbStore.Key[] = [];
|
||||
const validKeys: string[] = [];
|
||||
const invalidKeys: string[] = [];
|
||||
|
||||
// @ts-expect-error See https://github.com/DoctorEvidence/lmdb-store/pull/18
|
||||
for (const { key, value } of this.atimes.getRange()) {
|
||||
const atime = parseInt(`${value}`, 10);
|
||||
if (Number.isNaN(atime) || atime < ATIME_LIMIT) {
|
||||
const atime = parseInt(value, 10);
|
||||
if (atime < ATIME_LIMIT) {
|
||||
invalidKeys.push(key);
|
||||
} else {
|
||||
validKeys.push(key);
|
||||
|
|
50
yarn.lock
50
yarn.lock
|
@ -18798,28 +18798,16 @@ livereload-js@^2.3.0:
|
|||
resolved "https://registry.yarnpkg.com/livereload-js/-/livereload-js-2.4.0.tgz#447c31cf1ea9ab52fc20db615c5ddf678f78009c"
|
||||
integrity sha512-XPQH8Z2GDP/Hwz2PCDrh2mth4yFejwA1OZ/81Ti3LgKyhDcEjsSsqFWZojHG0va/duGd+WyosY7eXLDoOyqcPw==
|
||||
|
||||
lmdb-store-0.9@0.7.3:
|
||||
version "0.7.3"
|
||||
resolved "https://registry.yarnpkg.com/lmdb-store-0.9/-/lmdb-store-0.9-0.7.3.tgz#c2cb27dfa916ab966cceed692c67e4236813104a"
|
||||
integrity sha512-t8iCnN6T3NZPFelPmjYIjCg+nhGbOdc0xcHCG40v01AWRTN49OINSt2k/u+16/2/HrI+b6Ssb8WByXUhbyHz6w==
|
||||
lmdb-store@^0.6.10:
|
||||
version "0.6.10"
|
||||
resolved "https://registry.yarnpkg.com/lmdb-store/-/lmdb-store-0.6.10.tgz#db8efde6e052aabd17ebc63c8a913e1f31694129"
|
||||
integrity sha512-ZLvp3qbBQ5VlBmaWa4EUAPyYEZ8qdUHsW69HmxkDi84pFQ37WMxYhFaF/7PQkdtxS/vyiKkZigd9TFgHjek1Nw==
|
||||
dependencies:
|
||||
fs-extra "^9.0.1"
|
||||
msgpackr "^0.5.3"
|
||||
msgpackr "^0.5.0"
|
||||
nan "^2.14.1"
|
||||
node-gyp-build "^4.2.3"
|
||||
weak-lru-cache "^0.3.9"
|
||||
|
||||
lmdb-store@^0.8.15:
|
||||
version "0.8.15"
|
||||
resolved "https://registry.yarnpkg.com/lmdb-store/-/lmdb-store-0.8.15.tgz#4efb0341c2df505dd6f3a7f26f834f0a142a80a2"
|
||||
integrity sha512-4Q0WZh2FmcJC6esZRUWMfkCmNiz0WU9cOgrxt97ZMTnVfHyOdZhtrt0oOF5EQPfetxxJf/BorKY28aX92R6G6g==
|
||||
dependencies:
|
||||
fs-extra "^9.0.1"
|
||||
lmdb-store-0.9 "0.7.3"
|
||||
msgpackr "^0.5.4"
|
||||
nan "^2.14.1"
|
||||
node-gyp-build "^4.2.3"
|
||||
weak-lru-cache "^0.3.9"
|
||||
weak-lru-cache "^0.2.0"
|
||||
|
||||
load-bmfont@^1.3.1, load-bmfont@^1.4.0:
|
||||
version "1.4.0"
|
||||
|
@ -20335,20 +20323,20 @@ ms@2.1.1, ms@^2.0.0, ms@^2.1.1:
|
|||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"
|
||||
integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==
|
||||
|
||||
msgpackr-extract@^0.3.5:
|
||||
version "0.3.5"
|
||||
resolved "https://registry.yarnpkg.com/msgpackr-extract/-/msgpackr-extract-0.3.5.tgz#0f206da058bd3dad0f8605d324de001a8f4de967"
|
||||
integrity sha512-zHhstybu+m/j3H6CVBMcILVIzATK6dWRGtlePJjsnSAj8kLT5joMa9i0v21Uc80BPNDcwFsnG/dz2318tfI81w==
|
||||
msgpackr-extract@^0.3.4:
|
||||
version "0.3.4"
|
||||
resolved "https://registry.yarnpkg.com/msgpackr-extract/-/msgpackr-extract-0.3.4.tgz#8ee5e73d1135340e564c498e8c593134365eb060"
|
||||
integrity sha512-d3+qwTJzgqqsq2L2sQuH0SoO4StvpUhMqMAKy6tMimn7XdBaRtDlquFzRJsp0iMGt2hnU4UOqD8Tz9mb0KglTA==
|
||||
dependencies:
|
||||
nan "^2.14.1"
|
||||
node-gyp-build "^4.2.3"
|
||||
|
||||
msgpackr@^0.5.3, msgpackr@^0.5.4:
|
||||
version "0.5.4"
|
||||
resolved "https://registry.yarnpkg.com/msgpackr/-/msgpackr-0.5.4.tgz#c21c03d5e132d2e54d0b9ced02a75b1f48413380"
|
||||
integrity sha512-ILEWtIWwd5ESWHKoVjJ4GP7JWkpuAUJ20qi2j2qEC6twecBmK4E6YG3QW847OpmvdAhMJGq2LoDJRn/kNERTeQ==
|
||||
msgpackr@^0.5.0:
|
||||
version "0.5.1"
|
||||
resolved "https://registry.yarnpkg.com/msgpackr/-/msgpackr-0.5.1.tgz#7eecbf342645b7718dd2e3386894368d06732b3f"
|
||||
integrity sha512-nK2uJl67Q5KU3MWkYBUlYynqKS1UUzJ5M1h6TQejuJtJzD3hW2Suv2T1pf01E9lUEr93xaLokf/xC+jwBShMPQ==
|
||||
optionalDependencies:
|
||||
msgpackr-extract "^0.3.5"
|
||||
msgpackr-extract "^0.3.4"
|
||||
|
||||
multicast-dns-service-types@^1.1.0:
|
||||
version "1.1.0"
|
||||
|
@ -29141,10 +29129,10 @@ wcwidth@^1.0.1:
|
|||
dependencies:
|
||||
defaults "^1.0.3"
|
||||
|
||||
weak-lru-cache@^0.3.9:
|
||||
version "0.3.9"
|
||||
resolved "https://registry.yarnpkg.com/weak-lru-cache/-/weak-lru-cache-0.3.9.tgz#9e56920d4115e8542625d8ef8cc278cbd97f7624"
|
||||
integrity sha512-WqAu3wzbHQvjSi/vgYhidZkf2p7L3Z8iDEIHnqvE31EQQa7Vh7PDOphrRJ1oxlW8JIjgr2HvMcRe9Q1GhW2NPw==
|
||||
weak-lru-cache@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/weak-lru-cache/-/weak-lru-cache-0.2.0.tgz#447379ccff6dfda1b7a9566c9ef168260be859d1"
|
||||
integrity sha512-M1l5CzKvM7maa7tCbtL0NW6sOnp8gqup853+9Aq7GL0XNWKNnFOkeE3v3Z5X2IeMzedPwQyPbi4RlFvD6rxs7A==
|
||||
|
||||
web-namespaces@^1.0.0:
|
||||
version "1.1.4"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue