Skip to content

Tidy up and remove redundant json output path #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 25, 2024
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
85 changes: 0 additions & 85 deletions src/backend/access/common/printtup.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "tcop/pquery.h"
#include "utils/json.h"
#include "utils/lsyscache.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"

#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif

static void printtup_startup(DestReceiver *self, int operation,
TupleDesc typeinfo);
Expand Down Expand Up @@ -487,84 +483,3 @@ debugtup(TupleTableSlot *slot, DestReceiver *self)

return true;
}

/* ----------------------------------------------------------------
* printtup json
* ----------------------------------------------------------------
*/

StringInfoData json_result;

#ifdef EMSCRIPTEN
EM_JS(void, dispatch_result, (char *res), {
// Dispatch the result to JS land
var query_result = UTF8ToString(res);
var event = new Module.Event("result", {
detail: { result: query_result },
});
Module.eventTarget.dispatchEvent(event);
});
#endif

void
debugtup_json_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
{
MemoryContext oldcxt = MemoryContextSwitchTo(TopMemoryContext);

if (!json_result.data)
initStringInfo(&json_result);
else
resetStringInfo(&json_result);

appendStringInfoChar(&json_result, '[');

MemoryContextSwitchTo(oldcxt);
}

bool
debugtup_json(TupleTableSlot *slot, DestReceiver *self)
{
TupleDesc tupdesc = slot->tts_tupleDescriptor;
int i;
bool needsep = false;

/* without tuples json_result contain only '[', so len is 1 */
if (json_result.len > 1)
appendStringInfoChar(&json_result, ',');

appendStringInfoChar(&json_result, '{');

for (i = 0; i < tupdesc->natts; i++)
{
Datum val;
bool isnull;
char *attname;
Form_pg_attribute att = TupleDescAttr(tupdesc, i);

if (att->attisdropped)
continue;

if (needsep)
appendStringInfoString(&json_result, ",");
needsep = true;

attname = NameStr(att->attname);
escape_json(&json_result, attname);
appendStringInfoChar(&json_result, ':');

val = slot_getattr(slot, i + 1, &isnull);
add_json(val, isnull, &json_result, att->atttypid, false);
}

appendStringInfoChar(&json_result, '}');

return true;
}

void
debugtup_json_shutdown(DestReceiver *self)
{
appendStringInfoChar(&json_result, ']');
appendStringInfoChar(&json_result, '\0');
dispatch_result(json_result.data);
}
6 changes: 1 addition & 5 deletions src/backend/access/transam/slru.c
Original file line number Diff line number Diff line change
Expand Up @@ -1557,8 +1557,6 @@ SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
int segno;
int segpage;

elog(LOG, "! SlruScanDirectory start %s, %s", getcwd(NULL, 100), ctl->Dir);

cldir = AllocateDir(ctl->Dir);
while ((clde = ReadDir(cldir, ctl->Dir)) != NULL)
{
Expand All @@ -1572,7 +1570,7 @@ SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
segno = (int) strtol(clde->d_name, NULL, 16);
segpage = segno * SLRU_PAGES_PER_SEGMENT;

elog(LOG, "SlruScanDirectory invoking callback on %s/%s",
elog(DEBUG2, "SlruScanDirectory invoking callback on %s/%s",
ctl->Dir, clde->d_name);
retval = callback(ctl, clde->d_name, segpage, data);
if (retval)
Expand All @@ -1581,8 +1579,6 @@ SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
}
FreeDir(cldir);

elog(LOG, "! SlruScanDirectory stop");

return retval;
}

Expand Down
2 changes: 0 additions & 2 deletions src/backend/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ main(int argc, char *argv[])
{
bool do_check_root = true;

printf("Hey-hey!\n");

/*
* If supported on the current platform, set up a handler to be called if
* the backend/postmaster crashes with a fatal signal or exception.
Expand Down
8 changes: 0 additions & 8 deletions src/backend/nodes/nodeFuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4000,32 +4000,24 @@ planstate_tree_walker(PlanState *planstate,
/* Guard against stack overflow due to overly complex plan trees */
check_stack_depth();

// printf("planstate_tree_walker1\n");

/* initPlan-s */
if (planstate_walk_subplans(planstate->initPlan, walker, context))
return true;

// printf("planstate_tree_walker2\n");

/* lefttree */
if (outerPlanState(planstate))
{
if (walker(outerPlanState(planstate), context))
return true;
}

// printf("planstate_tree_walker3\n");

/* righttree */
if (innerPlanState(planstate))
{
if (walker(innerPlanState(planstate), context))
return true;
}

// printf("planstate_tree_walker4\n");

/* special child plans */
switch (nodeTag(plan))
{
Expand Down
5 changes: 1 addition & 4 deletions src/backend/port/sysv_shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ PGSharedMemoryCreate(Size size,
struct stat statbuf;
Size sysvsize;

elog(NOTICE, "! Hacky way to init shared memory");
elog(NOTICE, "Init WASM shared memory");

/* Initialize new segment. */
hdr = (PGShmemHeader *) malloc(size);
Expand Down Expand Up @@ -691,9 +691,6 @@ PGSharedMemoryCreate(Size size,
memcpy(AnonymousShmem, hdr, sizeof(PGShmemHeader));
return (PGShmemHeader *) AnonymousShmem;




/*
* We use the data directory's ID info (inode and device numbers) to
* positively identify shmem segments associated with this data dir, and
Expand Down
34 changes: 18 additions & 16 deletions src/backend/postmaster/postmaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,22 +1501,24 @@ getInstallationPaths(const char *argv0)
*/
get_pkglib_path(my_exec_path, pkglib_path);

// /*
// * Verify that there's a readable directory there; otherwise the Postgres
// * installation is incomplete or corrupt. (A typical cause of this
// * failure is that the postgres executable has been moved or hardlinked to
// * some directory that's not a sibling of the installation lib/
// * directory.)
// */
// pdir = AllocateDir(pkglib_path);
// if (pdir == NULL)
// ereport(ERROR,
// (errcode_for_file_access(),
// errmsg("could not open directory \"%s\": %m",
// pkglib_path),
// errhint("This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
// my_exec_path)));
// FreeDir(pdir);
#ifndef EMSCRIPTEN
/*
* Verify that there's a readable directory there; otherwise the Postgres
* installation is incomplete or corrupt. (A typical cause of this
* failure is that the postgres executable has been moved or hardlinked to
* some directory that's not a sibling of the installation lib/
* directory.)
*/
pdir = AllocateDir(pkglib_path);
if (pdir == NULL)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open directory \"%s\": %m",
pkglib_path),
errhint("This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
my_exec_path)));
FreeDir(pdir);
#endif

/*
* XXX is it worth similarly checking the share/ directory? If the lib/
Expand Down
3 changes: 0 additions & 3 deletions src/backend/storage/smgr/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,6 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
errhint("Check free disk space.")));
}

// printf("! writing block %u in file \"%s\"\n",
// blocknum, FilePathName(v->mdfd_vfd));

if (!skipFsync && !SmgrIsTemp(reln))
register_dirty_segment(reln, forknum, v);
}
Expand Down
11 changes: 0 additions & 11 deletions src/backend/tcop/dest.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ static const DestReceiver debugtupDR = {
DestDebug
};

static const DestReceiver debugtup_jsonDR = {
debugtup_json, debugtup_json_startup, debugtup_json_shutdown, donothingCleanup,
DestDebugJson
};

static const DestReceiver printsimpleDR = {
printsimple, printsimple_startup, donothingCleanup, donothingCleanup,
DestRemoteSimple
Expand Down Expand Up @@ -137,9 +132,6 @@ CreateDestReceiver(CommandDest dest)
case DestDebug:
return unconstify(DestReceiver *, &debugtupDR);

case DestDebugJson:
return unconstify(DestReceiver *, &debugtup_jsonDR);

case DestSPI:
return unconstify(DestReceiver *, &spi_printtupDR);

Expand Down Expand Up @@ -208,7 +200,6 @@ EndCommand(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_o

case DestNone:
case DestDebug:
case DestDebugJson:
case DestSPI:
case DestTuplestore:
case DestIntoRel:
Expand Down Expand Up @@ -254,7 +245,6 @@ NullCommand(CommandDest dest)

case DestNone:
case DestDebug:
case DestDebugJson:
case DestSPI:
case DestTuplestore:
case DestIntoRel:
Expand Down Expand Up @@ -298,7 +288,6 @@ ReadyForQuery(CommandDest dest)

case DestNone:
case DestDebug:
case DestDebugJson:
case DestSPI:
case DestTuplestore:
case DestIntoRel:
Expand Down
19 changes: 9 additions & 10 deletions src/backend/tcop/postgres.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
const char *debug_query_string; /* client-supplied query string */

/* Note: whereToSendOutput is initialized for the bootstrap/standalone case */
CommandDest whereToSendOutput = DestRemote;
CommandDest whereToSendOutput = DestDebug;

/* flag for logging end of session */
bool Log_disconnections = false;
Expand Down Expand Up @@ -315,8 +315,6 @@ InteractiveBackend(StringInfo inBuf)
* Even though we are not reading from a "client" process, we still want to
* respond to signals, particularly SIGTERM/SIGQUIT.
*/
// FILE *query_in = NULL;

static int
interactive_getc(void)
{
Expand All @@ -330,11 +328,6 @@ interactive_getc(void)
*/
CHECK_FOR_INTERRUPTS();

// if (!query_in) {
// printf("Reading query now\n");
// query_in = fopen("/Users/stas/datadir/q.sql","r");
// }

c = getc(stdin);

ProcessClientReadInterrupt(false);
Expand Down Expand Up @@ -529,9 +522,11 @@ ReadCommand(StringInfo inBuf)
int result;

if (whereToSendOutput == DestRemote)
#ifdef EMSCRIPTEN
result = EmscriptenBackend(inBuf);
else if (whereToSendOutput == DestDebugJson)
result = EmscriptenBackend(inBuf);
#else
result = SocketBackend(inBuf);
#endif
else
result = InteractiveBackend(inBuf);
return result;
Expand Down Expand Up @@ -3749,6 +3744,10 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
{
argv++;
argc--;
#ifdef EMSCRIPTEN
/* We want to send output to the client using the wire protocol */
whereToSendOutput = DestRemote;
#endif
}
}
else
Expand Down
4 changes: 3 additions & 1 deletion src/backend/utils/adt/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ static void json_categorize_type(Oid typoid,
static void datum_to_json(Datum val, bool is_null, StringInfo result,
JsonTypeCategory tcategory, Oid outfuncoid,
bool key_scalar);
static void add_json(Datum val, bool is_null, StringInfo result,
Oid val_type, bool key_scalar);
static text *catenate_stringinfo_string(StringInfo buffer, const char *addon);

/*
Expand Down Expand Up @@ -630,7 +632,7 @@ composite_to_json(Datum composite, StringInfo result, bool use_line_feeds)
* printed many times, avoid using this; better to do the json_categorize_type
* lookups only once.
*/
void
static void
add_json(Datum val, bool is_null, StringInfo result,
Oid val_type, bool key_scalar)
{
Expand Down
Loading