Skip to content

Commit

Permalink
Series of mechanical code beautifications to support Apache Cloudberry (
Browse files Browse the repository at this point in the history
#119)

* Series of mechanical code beautifications to support Apache Cloudberry

* Add more
  • Loading branch information
reshke authored Feb 22, 2025
1 parent 412c4e7 commit a6a8feb
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 19 deletions.
1 change: 1 addition & 0 deletions include/msgproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstring>
#include <string>
#include <vector>
#include <cstdint>

const char DecryptRequest = 1;
const char NoDecryptRequest = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::string make_yezzey_url(const std::string &prefix, int64_t modcounts,
std::vector<int64_t> parseModcounts(const std::string &prefix,
std::string name);

std::string resolve_temp_relname(char *tempname);
std::string resolve_temp_relname(const char *tempname);
#endif

EXTERNC void
Expand Down
1 change: 1 addition & 0 deletions include/virtual_tablespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define YEZZEY_VIRTUAL_TABLESPACE

#include "pg.h"
#include "yezzey_meta.h"

#ifdef __cplusplus
#define EXTERNC extern "C"
Expand Down
9 changes: 9 additions & 0 deletions include/yezzey_heap_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
#define yezzey_systable_beginscan table_beginscan
#define yezzey_beginscan table_beginscan
#define yezzey_endscan table_endscan

/* catalog */

#define yezzey_beginscan_catalog table_beginscan_catalog

#else
#define yezzey_relation_open heap_open
#define yezzey_systable_beginscan systable_beginscan
#define yezzey_beginscan heap_beginscan
#define yezzey_endscan heap_endscan

/* catalog */
#define yezzey_beginscan_catalog heap_beginscan_catalog

#endif

#endif /* YEZZEY_HEAP_API_H */
7 changes: 6 additions & 1 deletion include/yezzey_meta.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#pragma once

#include "pg.h"
#include "url.h"
#include "virtual_index.h"
#include "ygpver.h"

#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC
#endif

#if IsModernYezzey
#define YEZZEY_AUX_NAMESPACE 8001
#define YEZZEYTABLESPACE_OID 8555
#endif

EXTERNC void YezzeyUpdateMetadataRelations(
Oid yandexoid /*yezzey auxiliary index oid*/, Oid reloid,
Oid relfilenodeOid, int64_t blkno, int64_t offset_start,
Expand Down
15 changes: 7 additions & 8 deletions smgr.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

#include "postgres.h"

#include "miscadmin.h"
// For GpIdentity
#include "c.h"
#include "cdb/cdbvars.h"

#if PG_VERSION_NUM >= 130000
#include "postmaster/interrupt.h"
#endif

#include "catalog/pg_tablespace.h"


// For GpIdentity
#include "c.h"
#include "cdb/cdbvars.h"
#if IsModernYezzey
#include "access/aomd.h"
#endif

#include "storage/ipc.h"
#include "storage/lwlock.h"
Expand All @@ -29,9 +30,7 @@
#include "utils/elog.h"
#include "utils/snapmgr.h"

#if IsModernYezzey
#include "access/aomd.h"
#endif
#include "miscadmin.h"

#include "storage.h"
#include "proxy.h"
Expand Down
9 changes: 8 additions & 1 deletion src/binary_upgrade.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@

/*
* Yezzey.
*/

#include "pg.h"

#include "binary_upgrade.h"
#include "offload_policy.h"
#include "pg.h"
#include "virtual_index.h"
#include "yezzey_heap_api.h"
#include "yezzey_meta.h"

void YezzeyBinaryUpgrade(void) {
/**/
Expand Down
1 change: 1 addition & 0 deletions src/msgproto.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "msgproto.h"
#include <cstdint>

MsgBuilder::MsgBuilder() : length(UINT64_SZ), cursor(0), data() {}

Expand Down
4 changes: 3 additions & 1 deletion src/offload_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* file: src/offload_policy.cpp
*/


#include "yezzey_heap_api.h"
#include "offload_policy.h"
#include "offload.h"
#include "yezzey_heap_api.h"
#include <unistd.h>
#include "yezzey_meta.h"

#include "offload_tablespace_map.h"

Expand Down
14 changes: 10 additions & 4 deletions src/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include "offload_tablespace_map.h"
#include "url.h"
#include "virtual_index.h"
#include "yezzey_heap_api.h"
#include "yezzey_meta.h"
#include "ygpver.h"
#include "yproxy.h"
#include <iostream>

#define USE_YPX_LISTER = 1

Expand Down Expand Up @@ -283,7 +283,12 @@ bool ensureFileLocal(RelFileNode rnode, BackendId backend, ForkNumber forkNum,
BlockNumber blkno) {
/* MDB-19689: do not consult catalog */

#if IsModernYezzey
elog(yezzey_log_level, "ensuring %ld is local", rnode.relNode);
#else
elog(yezzey_log_level, "ensuring %d is local", rnode.relNode);
#endif

bool result = true;

auto path = std::string(relpathbackend(rnode, backend, forkNum));
Expand Down Expand Up @@ -373,8 +378,9 @@ int offloadRelationSegment(Relation aorel, int segno, int64 modcount,
return 0;
}

static Oid resolveTablespaceOidByName(std::string tablespacename) {

static Oid
resolveTablespaceOidByName(std::string tablespacename)
{
Relation rel;
HeapScanDesc scan;
HeapTuple tuple;
Expand All @@ -387,7 +393,7 @@ static Oid resolveTablespaceOidByName(std::string tablespacename) {

ScanKeyInit(&entry[0], Anum_pg_tablespace_spcname, BTEqualStrategyNumber,
F_NAMEEQ, CStringGetDatum(tablespacename.c_str()));
scan = heap_beginscan_catalog(rel, 1, entry);
scan = yezzey_beginscan_catalog(rel, 1, entry);
tuple = heap_getnext(scan, ForwardScanDirection);

if (!HeapTupleIsValid(tuple)) {
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ XLogRecPtr yezzeyGetXStorageInsertLsn(void) {
return GetXLogWriteRecPtr();
}

std::string resolve_temp_relname(char *tempname) {
std::string resolve_temp_relname(const char *tempname) {
std::string name(tempname);
if (strncmp(name.c_str(), "pg_temp_", 8) == 0) {
int oid = atoi(name.substr(8, name.find('_', 8)).c_str());
Expand Down
5 changes: 3 additions & 2 deletions src/virtual_index.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

#include "virtual_index.h"

#include "yezzey_heap_api.h"
#include <algorithm>
#include "yezzey_heap_api.h"

#include "yezzey_meta.h"

Oid YezzeyFindAuxIndex_internal(Oid reloid);

Expand Down
6 changes: 6 additions & 0 deletions src/virtual_tablespace.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

/*
* Yezzey
*/

#include "virtual_tablespace.h"
#include "yezzey_meta.h"

/*
* Execute ALTER TABLE SET TABLESPACE for cases where there is no tuple
Expand Down
4 changes: 4 additions & 0 deletions yezzey.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,5 +1344,9 @@ void _PG_init(void) {
ExecutorStart_hook = yezzey_ExecuterStartHook;
ExecutorEnd_hook = yezzey_ExecuterEndHook;

#if IsModernYezzey
/* Support? */
#else
TrackDropObject_hook = yezzey_TrackObjDrop;
#endif
}

0 comments on commit a6a8feb

Please sign in to comment.