Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ aliases:
GENERATE_JEST_REPORT: "true"
JEST_JUNIT_OUTPUT_DIR: ./test-results/jest-node/
JEST_JUNIT_OUTPUT_NAME: results.xml
GATSBY_EXPERIMENTAL_LMDB_STORE: 1
GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING: 1
- store_test_results:
path: ./test-results/jest-node/

Expand Down Expand Up @@ -529,7 +527,6 @@ jobs:
no_output_timeout: 15m
environment:
NODE_OPTIONS: --max-old-space-size=2048
GATSBY_EXPERIMENTAL_LMDB_STORE: 1
GENERATE_JEST_REPORT: "true"
COMPILER_OPTIONS: GATSBY_MAJOR=5
JEST_JUNIT_OUTPUT_DIR: ./test-results/jest-node/
Expand Down
3 changes: 0 additions & 3 deletions benchmarks/query-filters-sort/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ module.exports = {
description: `The filters and sort benchmark`,
author: `@gatsbyjs`,
},
flags: {
PARALLEL_QUERY_RUNNING: true,
}
// plugins: [`gatsby-plugin-benchmark-reporting`],
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Debugging Missing or Stale Data Fields on Nodes

## Overview of `LMDB` datastore behavior changes

In Gatsby 3 we introduced a new data store called `LMDB` (enabled with `LMDB_STORE` and/or `PARALLEL_QUERY_RUNNING` flags). In Gatsby 4 it became the default data store. It allows Gatsby to execute data layer related processing outside of the main build process and enables Gatsby to run queries in multiple processes as well as support additional rendering strategies ([DSG](/docs/reference/rendering-options/deferred-static-generation/) and [SSR](/docs/reference/rendering-options/server-side-rendering/)).
In Gatsby 3 we introduced a new data store called `LMDB`. In Gatsby 4 it became the default data store. It allows Gatsby to execute data layer related processing outside of the main build process and enables Gatsby to run queries in multiple processes as well as support additional rendering strategies ([DSG](/docs/reference/rendering-options/deferred-static-generation/) and [SSR](/docs/reference/rendering-options/server-side-rendering/)).

In a lot of cases that change is completely invisible to users, but there are cases where things behave differently.

Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/development-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "cross-env CYPRESS_SUPPORT=y ENABLE_GATSBY_REFRESH_ENDPOINT=true GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND=y gatsby develop",
"develop": "cross-env CYPRESS_SUPPORT=y ENABLE_GATSBY_REFRESH_ENDPOINT=y GATSBY_ENABLE_QUERY_ON_DEMAND_IN_CI=y gatsby develop",
"serve-static-files": "node ./serve-static-files.mjs",
"serve": "gatsby serve",
"clean": "gatsby clean",
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/gatsby-cli/__tests__/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe(`gatsby build`, () => {
logs.should.contain(
`success Building production JavaScript and CSS bundles`
)
logs.should.contain(`success run page queries`)
logs.should.contain(`run queries in workers`)
logs.should.contain(`success Building static HTML for pages`)
logs.should.contain(`success onPostBuild`)
logs.should.contain(`info Done building`)
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/node-manifest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"test": "cross-env GATSBY_COMMAND_NAME=build jest --runInBand && cross-env GATSBY_COMMAND_NAME=develop jest --runInBand"
},
"author": "Tyler Barnes <[email protected]>",
"license": "ISC",
"license": "MIT",
"dependencies": {
"gatsby": "next",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"cross-env": "^7.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ apiRunnerAsync(`onClientEntry`).then(() => {

let dismissLoadingIndicator
if (
process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND &&
process.env.GATSBY_QUERY_ON_DEMAND &&
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR === `true`
) {
let indicatorMountElement
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/dev-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DevLoader extends BaseLoader {
}

doPrefetch(pagePath) {
if (process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND) {
if (process.env.GATSBY_QUERY_ON_DEMAND) {
return Promise.resolve()
}
return super.doPrefetch(pagePath).then(result => result.payload)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const onRouteUpdate = (location, prevLocation) => {
if (!maybeRedirect(location.pathname)) {
apiRunner(`onRouteUpdate`, { location, prevLocation })
if (
process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND &&
process.env.GATSBY_QUERY_ON_DEMAND &&
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR === `true`
) {
emitter.emit(`onRouteUpdate`, { location, prevLocation })
Expand Down
18 changes: 6 additions & 12 deletions packages/gatsby/src/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ export async function bootstrap(

const workerPool = context.workerPool

if (process.env.GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING) {
const program = context.store.getState().program
const directory = slash(program.directory)
const program = context.store.getState().program
const directory = slash(program.directory)

workerPool.all.loadConfigAndPlugins({ siteDirectory: directory, program })
}
workerPool.all.loadConfigAndPlugins({ siteDirectory: directory, program })

await customizeSchema(context)
await sourceNodes(context)
Expand All @@ -69,17 +67,13 @@ export async function bootstrap(

await handleStalePageData(parentSpan)

if (process.env.GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING) {
savePartialStateToDisk([`inferenceMetadata`])
savePartialStateToDisk([`inferenceMetadata`])

workerPool.all.buildSchema()
}
workerPool.all.buildSchema()

await extractQueries(context)

if (process.env.GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING) {
savePartialStateToDisk([`components`, `staticQueryComponents`])
}
savePartialStateToDisk([`components`, `staticQueryComponents`])

await writeOutRedirects(context)

Expand Down
34 changes: 20 additions & 14 deletions packages/gatsby/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import report from "gatsby-cli/lib/reporter"
import signalExit from "signal-exit"
import fs from "fs-extra"
import telemetry from "gatsby-telemetry"
import { updateInternalSiteMetadata, isTruthy, uuid } from "gatsby-core-utils"
import {
updateInternalSiteMetadata,
isTruthy,
uuid,
cpuCoreCount,
} from "gatsby-core-utils"
import {
buildRenderer,
buildHTMLPagesAndDeleteStaleArtifacts,
Expand Down Expand Up @@ -336,19 +341,8 @@ module.exports = async function build(
const waitMaterializePageMode = materializePageMode()

let waitForWorkerPoolRestart = Promise.resolve()
if (process.env.GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING) {
await runQueriesInWorkersQueue(workerPool, queryIds, {
parentSpan: buildSpan,
})
// Jobs still might be running even though query running finished
await Promise.all([
waitUntilAllJobsComplete(),
waitUntilWorkerJobsAreComplete(),
])
// Restart worker pool before merging state to lower memory pressure while merging state
waitForWorkerPoolRestart = workerPool.restart()
await mergeWorkerState(workerPool, buildSpan)
} else {
// If one wants to debug query running you can set the CPU count to 1
if (cpuCoreCount() === 1) {
await runStaticQueries({
queryIds,
parentSpan: buildSpan,
Expand All @@ -362,6 +356,18 @@ module.exports = async function build(
parentSpan: buildSpan,
store,
})
} else {
await runQueriesInWorkersQueue(workerPool, queryIds, {
parentSpan: buildSpan,
})
// Jobs still might be running even though query running finished
await Promise.all([
waitUntilAllJobsComplete(),
waitUntilWorkerJobsAreComplete(),
])
// Restart worker pool before merging state to lower memory pressure while merging state
waitForWorkerPoolRestart = workerPool.restart()
await mergeWorkerState(workerPool, buildSpan)
}

if (_CFLAGS_.GATSBY_MAJOR === `5` && process.env.GATSBY_SLICES) {
Expand Down
5 changes: 1 addition & 4 deletions packages/gatsby/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ import {
import { reverseFixedPagePath } from "../utils/page-data"
import { initTracer } from "../utils/tracer"
import { configureTrailingSlash } from "../utils/express-middlewares"
import { getDataStore, detectLmdbStore } from "../datastore"
import { getDataStore } from "../datastore"
import { functionMiddlewares } from "../internal-plugins/functions/middleware"
import {
thirdPartyProxyPath,
partytownProxy,
} from "../internal-plugins/partytown/proxy"

process.env.GATSBY_EXPERIMENTAL_LMDB_STORE = `1`
detectLmdbStore()

interface IMatchPath {
path: string
matchPath: string
Expand Down
36 changes: 2 additions & 34 deletions packages/gatsby/src/datastore/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,15 @@ import { IDataStore } from "./types"
import { emitter } from "../redux"

let dataStore: IDataStore
let isLmdb = isLmdbStoreFlagSet()

export function getDataStore(): IDataStore {
if (!dataStore) {
if (isLmdb) {
const { setupLmdbStore } = require(`./lmdb/lmdb-datastore`)
dataStore = setupLmdbStore()
} else {
const { setupInMemoryStore } = require(`./in-memory/in-memory-datastore`)
dataStore = setupInMemoryStore()
}
const { setupLmdbStore } = require(`./lmdb/lmdb-datastore`)
dataStore = setupLmdbStore()
}
return dataStore
}

export function isLmdbStore(): boolean {
return isLmdb
}

export function detectLmdbStore(): boolean {
const flagIsSet = isLmdbStoreFlagSet()

if (dataStore && isLmdb !== flagIsSet) {
throw new Error(
`GATSBY_EXPERIMENTAL_LMDB_STORE flag had changed after the data store was initialized.` +
`(original value: ${isLmdb ? `true` : `false`}, ` +
`new value: ${flagIsSet ? `true` : `false`})`
)
}
isLmdb = flagIsSet
return flagIsSet
}

function isLmdbStoreFlagSet(): boolean {
return (
Boolean(process.env.GATSBY_EXPERIMENTAL_LMDB_STORE) &&
process.env.GATSBY_EXPERIMENTAL_LMDB_STORE !== `false` &&
process.env.GATSBY_EXPERIMENTAL_LMDB_STORE !== `0`
)
}

// It is possible that the store is not initialized yet when calling `DELETE_CACHE`.
// The code below ensures we wipe cache from the proper store
// (mostly relevant for tests)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/datastore/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IGatsbyNode } from "../redux/types"
import { getDataStore } from "./datastore"

export { getDataStore, isLmdbStore, detectLmdbStore } from "./datastore"
export { getDataStore } from "./datastore"

// Convenience accessor methods

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/query/query-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export async function queryRunner(
if (queryJob.queryType === `page` || queryJob.queryType === `slice`) {
// We need to save this temporarily in cache because
// this might be incomplete at the moment
await savePageQueryResult(program.directory, queryJob.id, resultJSON)
await savePageQueryResult(queryJob.id, resultJSON)
if (queryJob.queryType === `page`) {
store.dispatch({
type: `ADD_PENDING_PAGE_DATA_WRITE`,
Expand Down
Loading