Skip to content

Commit

Permalink
feat(swing-store): enable LMDB_MAP_SIZE and SOLO_LMDB_MAP_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Feb 11, 2022
1 parent 3a92849 commit 77f67a8
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 29 deletions.
24 changes: 22 additions & 2 deletions docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ Description: When nonempty, create pretend prepopulated tokens like "moola" and

Lifetime: until chain is mature enough not to need any pretend tokens

## LMDB_MAP_SIZE

Affects: cosmic-swingset

Purpose: set the minimum size limit for swing-store's LMDB key-value store

Description: default is `2147483648` (2GB), and you need to set higher if you
receive `Error: MDB_MAP_FULL: Environment mapsize limit reached`

Can always be increased, and does not decrease once a transaction has been
written with the new mapSize.

Lifetime: until we no longer use LMDB in swing-store

## OTEL_EXPORTER_PROMETHEUS_HOST
## OTEL_EXPORTER_PROMETHEUS_PORT

Expand All @@ -109,15 +123,21 @@ for the Prometheus scrape endpoint to export telemetry.

Lifetime: until we decide not to support Prometheus for metrics export

## SOLO_LMDB_MAP_SIZE

Affects: solo

Same as `LMDB_MAP_SIZE`, but for solo instead of chain.

## SOLO_SLOGFILE

Same as SLOGFILE, but for solo instead of chain.
Same as `SLOGFILE`, but for solo instead of chain.

Lifetime: ?

## SOLO_SLOGSENDER

Same as SLOGSENDER, but for solo instead of chain.
Same as `SLOGSENDER`, but for solo instead of chain.

Lifetime: ?

Expand Down
16 changes: 9 additions & 7 deletions packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,27 +251,29 @@ export default async function main(progname, args, { env, homedir, agcc }) {
).pathname;
const { metricsProvider } = getTelemetryProviders({ console, env });

const { SLOGFILE, SLOGSENDER } = env;
const { SLOGFILE, SLOGSENDER, LMDB_MAP_SIZE } = env;
const slogSender = await makeSlogSenderFromModule(SLOGSENDER, {
stateDir: stateDBDir,
});

const mapSize = (LMDB_MAP_SIZE && parseInt(LMDB_MAP_SIZE, 10)) || undefined;

// We want to make it hard for a validator to accidentally disable
// consensusMode.
const consensusMode = true;
const s = await launch(
stateDBDir,
const s = await launch({
kernelStateDBDir: stateDBDir,
mailboxStorage,
setActivityhash,
doOutboundBridge,
bridgeOutbound: doOutboundBridge,
vatconfig,
argv,
undefined,
metricsProvider,
SLOGFILE,
slogFile: SLOGFILE,
slogSender,
consensusMode,
);
mapSize,
});
return s;
}

Expand Down
17 changes: 10 additions & 7 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
loadSwingsetConfigFile,
} from '@agoric/swingset-vat';
import { assert, details as X } from '@agoric/assert';
import { openSwingStore } from '@agoric/swing-store';
import { openSwingStore, DEFAULT_LMDB_MAP_SIZE } from '@agoric/swing-store';
import {
DEFAULT_METER_PROVIDER,
exportKernelStats,
Expand Down Expand Up @@ -135,31 +135,34 @@ function neverStop() {
});
}

export async function launch(
export async function launch({
kernelStateDBDir,
mailboxStorage,
setActivityhash,
bridgeOutbound,
vatconfig,
argv,
debugName = undefined,
meterProvider = DEFAULT_METER_PROVIDER,
metricsProvider = DEFAULT_METER_PROVIDER,
slogFile = undefined,
slogSender,
consensusMode = true,
) {
mapSize = DEFAULT_LMDB_MAP_SIZE,
}) {
console.info('Launching SwingSet kernel');

const { kvStore, streamStore, snapStore, commit } =
openSwingStore(kernelStateDBDir);
const { kvStore, streamStore, snapStore, commit } = openSwingStore(
kernelStateDBDir,
{ mapSize },
);
const hostStorage = {
kvStore,
streamStore,
snapStore,
};

// Not to be confused with the gas model, this meter is for OpenTelemetry.
const metricMeter = meterProvider.getMeter('ag-chain-cosmos');
const metricMeter = metricsProvider.getMeter('ag-chain-cosmos');
const METRIC_LABELS = { app: 'ag-chain-cosmos' };

const slogCallbacks = makeSlogCallbacks({
Expand Down
16 changes: 8 additions & 8 deletions packages/cosmic-swingset/src/sim-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
env: process.env,
});

const { SLOGFILE, SLOGSENDER } = process.env;
const { SLOGFILE, SLOGSENDER, LMDB_MAP_SIZE } = process.env;
const mapSize = (LMDB_MAP_SIZE && parseInt(LMDB_MAP_SIZE, 10)) || undefined;
const slogSender = await makeSlogSenderFromModule(SLOGSENDER, {
stateDir: stateDBdir,
});

// We don't want to force a sim chain to use consensus mode.
const consensusMode = false;
const s = await launch(
stateDBdir,
const s = await launch({
kernelStateDBDir: stateDBdir,
mailboxStorage,
undefined,
undefined,
vatconfig,
argv,
GCI, // debugName
debugName: GCI,
metricsProvider,
SLOGFILE,
slogFile: SLOGFILE,
slogSender,
consensusMode,
);
mapSize,
});

const { savedHeight, savedActions, savedChainSends } = s;
const blockManager = makeBlockManager({ ...s, flushChainSends });
Expand Down
14 changes: 11 additions & 3 deletions packages/solo/src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,17 @@ const buildSwingset = async (
plugin: { ...plugin.endowments },
};

const { kvStore, streamStore, snapStore, commit } =
openSwingStore(kernelStateDBDir);
const {
SOLO_SLOGFILE: slogFile,
SOLO_SLOGSENDER,
SOLO_LMDB_MAP_SIZE,
} = process.env;
const mapSize =
(SOLO_LMDB_MAP_SIZE && parseInt(SOLO_LMDB_MAP_SIZE, 10)) || undefined;
const { kvStore, streamStore, snapStore, commit } = openSwingStore(
kernelStateDBDir,
{ mapSize },
);
const hostStorage = {
kvStore,
streamStore,
Expand All @@ -158,7 +167,6 @@ const buildSwingset = async (
}
await initializeSwingset(config, argv, hostStorage);
}
const { SOLO_SLOGFILE: slogFile, SOLO_SLOGSENDER } = process.env;
const slogSender = await makeSlogSenderFromModule(SOLO_SLOGSENDER, {
stateDir: kernelStateDBDir,
});
Expand Down
12 changes: 10 additions & 2 deletions packages/swing-store/src/swingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { sqlStreamStore } from './sqlStreamStore.js';
import { makeSnapStore } from './snapStore.js';
import { initEphemeralSwingStore } from './ephemeralSwingStore.js';

export const DEFAULT_LMDB_MAP_SIZE = 2 * 1024 * 1024 * 1024;

export { makeSnapStore };

export function makeSnapStoreIO() {
Expand Down Expand Up @@ -126,12 +128,18 @@ function makeSwingStore(dirPath, forceReset, options) {
}
fs.mkdirSync(dirPath, { recursive: true });

const { mapSize = 2 * 1024 * 1024 * 1024 } = options;
const { mapSize = DEFAULT_LMDB_MAP_SIZE } = options;
let lmdbEnv = new lmdb.Env();

// Use the new mapSize, persisting if it's bigger than before and there's a
// write txn commit.
// http://www.lmdb.tech/doc/group__mdb.html#gaa2506ec8dab3d969b0e609cd82e619e5
lmdbEnv.resize(mapSize);

lmdbEnv.open({
path: dirPath,
mapSize,
// Turn off useWritemap on the Mac. The userWritemap option is currently
// Turn off useWritemap on the Mac. The useWritemap option is currently
// required for LMDB to function correctly on Linux running under WSL, but
// we don't yet have a convenient recipe to probe our environment at
// runtime to distinguish that species of Linux from the others. For now
Expand Down

0 comments on commit 77f67a8

Please sign in to comment.