Skip to content
Draft
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
71 changes: 71 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# the official .clang-format style for https://github.com/taocpp
#
# clang-format-4.0 -i -style=file $(find -name '[^.]*.[hc]pp')

Language: Cpp
Standard: Cpp11

AccessModifierOffset: -3
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum : true
AfterFunction : true
AfterNamespace : true
AfterStruct : true
AfterUnion : true
BeforeCatch : true
BeforeElse : true
IndentBraces : false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakStringLiterals: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 3
ContinuationIndentWidth: 3
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentWidth: 3
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: false
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: true
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
TabWidth: 8
UseTab: Never
5 changes: 5 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CompileFlags:
CompilationDatabase: build/ # Search build/ directory for compile_commands.json
Remove: [ -Werror ]
Add: [ -DPGDLLIMPORT= ]

2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
watch_file flake.nix
use flake
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ lib*.pc
/Release/
/tmp_install/
/portlock/

build/
install/
test-db/
.direnv/
.cache/
.history

8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

580 changes: 580 additions & 0 deletions .idea/editor.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Attach Postgres",
"type": "cppdbg",
"request": "attach",
"program": "${workspaceRoot}/install/bin/postgres",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"syscache.h": "c",
"random": "c"
}
}
31 changes: 15 additions & 16 deletions contrib/pg_prewarm/autoprewarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ apw_load_buffers(void)
apw_state->prewarm_start_idx = apw_state->prewarm_stop_idx = 0;
apw_state->prewarmed_blocks = 0;


/* Don't prewarm more than we can fit. */
if (num_elements > NBuffers)
{
num_elements = NBuffers;
ereport(LOG,
(errmsg("autoprewarm: capping prewarmed blocks to %d (shared_buffers size)",
NBuffers)));
}

/* Get the info position of the first block of the next database. */
while (apw_state->prewarm_start_idx < num_elements)
{
Expand Down Expand Up @@ -410,10 +420,6 @@ apw_load_buffers(void)
apw_state->database = current_db;
Assert(apw_state->prewarm_start_idx < apw_state->prewarm_stop_idx);

/* If we've run out of free buffers, don't launch another worker. */
if (!have_free_buffer())
break;

/*
* Likewise, don't launch if we've already been told to shut down.
* (The launch would fail anyway, but we might as well skip it.)
Expand Down Expand Up @@ -462,12 +468,6 @@ apw_read_stream_next_block(ReadStream *stream,
{
BlockInfoRecord blk = p->block_info[p->pos];

if (!have_free_buffer())
{
p->pos = apw_state->prewarm_stop_idx;
return InvalidBlockNumber;
}

if (blk.tablespace != p->tablespace)
return InvalidBlockNumber;

Expand Down Expand Up @@ -523,10 +523,10 @@ autoprewarm_database_main(Datum main_arg)
blk = block_info[i];

/*
* Loop until we run out of blocks to prewarm or until we run out of free
* Loop until we run out of blocks to prewarm or until we run out of
* buffers.
*/
while (i < apw_state->prewarm_stop_idx && have_free_buffer())
while (i < apw_state->prewarm_stop_idx)
{
Oid tablespace = blk.tablespace;
RelFileNumber filenumber = blk.filenumber;
Expand Down Expand Up @@ -568,14 +568,13 @@ autoprewarm_database_main(Datum main_arg)

/*
* We have a relation; now let's loop until we find a valid fork of
* the relation or we run out of free buffers. Once we've read from
* all valid forks or run out of options, we'll close the relation and
* the relation or we run out of buffers. Once we've read from all
* valid forks or run out of options, we'll close the relation and
* move on.
*/
while (i < apw_state->prewarm_stop_idx &&
blk.tablespace == tablespace &&
blk.filenumber == filenumber &&
have_free_buffer())
blk.filenumber == filenumber)
{
ForkNumber forknum = blk.forknum;
BlockNumber nblocks;
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
description = "PostgreSQL development environment";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = {
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};

shellConfig = import ./shell.nix {inherit pkgs system;};
in {
formatter = pkgs.alejandra;
devShells = {
default = shellConfig.devShell;
gcc = shellConfig.devShell;
clang = shellConfig.clangDevShell;
gcc-musl = shellConfig.muslDevShell;
clang-musl = shellConfig.clangMuslDevShell;
};

packages = {
inherit (shellConfig) gdbConfig flameGraphScript pgbenchScript;
};

environment.localBinInPath = true;
}
);
}
Loading