Skip to content

Commit 8749e3e

Browse files
committed
slightly format after merge
1 parent 89e4134 commit 8749e3e

4 files changed

Lines changed: 54 additions & 64 deletions

File tree

src/kv_fdw.c

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static void GetForeignRelSize(PlannerInfo *root,
5353
* min & max will call GetForeignRelSize & GetForeignPaths multiple times,
5454
* we should open & close db multiple times.
5555
*/
56-
printf("\n-----------------%s open----------------------\n", __func__);
5756
ptr = OpenRequest(foreignTableId, ptr);
5857

5958
/* TODO better estimation */
@@ -190,26 +189,28 @@ static void GetKeyRangeQual(Plan *plan,
190189
continue;
191190
}
192191

193-
HeapTuple opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(op->opno));
192+
HeapTuple opertup = SearchSysCache1(OPEROID,
193+
ObjectIdGetDatum(op->opno));
194194
if (!HeapTupleIsValid(opertup)) {
195-
ereport(ERROR, (errmsg("cache lookup failed for operator %u", op->opno)));
195+
ereport(ERROR, (errmsg("cache lookup failed for operator %u",
196+
op->opno)));
196197
}
197198
Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
198199
char *oprname = NameStr(operform->oprname);
199200
if (strncmp(oprname, ">=", NAMEDATALEN) == 0) {
200201
startFlag = true;
201202
Const *constNode = ((Const *) right);
202203
Datum datum = constNode->constvalue;
203-
TypeCacheEntry *typeEntry = lookup_type_cache(constNode->consttype, 0);
204-
datum = ShortVarlena(datum, typeEntry->typlen, typeEntry->typstorage);
204+
TypeCacheEntry *type = lookup_type_cache(constNode->consttype, 0);
205+
datum = ShortVarlena(datum, type->typlen, type->typstorage);
205206
SerializeAttribute(tupleDescriptor, varattno-1, datum, startInfo);
206207
ReleaseSysCache(opertup);
207208
}else if (strncmp(oprname, "<=", NAMEDATALEN) == 0) {
208209
limitFlag = true;
209210
Const *constNode = ((Const *) right);
210211
Datum datum = constNode->constvalue;
211-
TypeCacheEntry *typeEntry = lookup_type_cache(constNode->consttype, 0);
212-
datum = ShortVarlena(datum, typeEntry->typlen, typeEntry->typstorage);
212+
TypeCacheEntry *type = lookup_type_cache(constNode->consttype, 0);
213+
datum = ShortVarlena(datum, type->typlen, type->typstorage);
213214
SerializeAttribute(tupleDescriptor, varattno-1, datum, limitInfo);
214215
ReleaseSysCache(opertup);
215216
}else{
@@ -258,7 +259,8 @@ static void GetKeyBasedQual(Node *node,
258259
/* get the name of the operator according to PG_OPERATOR OID */
259260
HeapTuple opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(op->opno));
260261
if (!HeapTupleIsValid(opertup)) {
261-
ereport(ERROR, (errmsg("cache lookup failed for operator %u", op->opno)));
262+
ereport(ERROR, (errmsg("cache lookup failed for operator %u",
263+
op->opno)));
262264
}
263265
Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
264266
char *oprname = NameStr(operform->oprname);
@@ -324,13 +326,9 @@ static void BeginForeignScan(ForeignScanState *scanState, int executorFlags) {
324326
return;
325327
}
326328

327-
//printf("\n-----------------Plan Type: %d----------------------\n", scanState->ss.ps.plan->type);
328-
329329
ListCell *lc;
330330
foreach (lc, scanState->ss.ps.plan->qual) {
331331
Expr *state = lfirst(lc);
332-
//printf("\n-----------------Qual Type: %d----------------------\n", state->type);
333-
334332
GetKeyBasedQual((Node *) state,
335333
scanState->ss.ss_currentRelation->rd_att,
336334
readState);
@@ -346,18 +344,13 @@ static void BeginForeignScan(ForeignScanState *scanState, int executorFlags) {
346344
scanState->ss.ss_currentRelation->rd_att,
347345
readState);
348346
#endif
349-
//if(readState->isRangeQueryUsed) {
350-
351-
//}else
352-
//{
353-
Oid relationId = RelationGetRelid(scanState->ss.ss_currentRelation);
354-
GetIterRequest(relationId, ptr);
355-
//}
347+
Oid relationId = RelationGetRelid(scanState->ss.ss_currentRelation);
348+
GetIterRequest(relationId, ptr);
356349
}
357350
}
358351

359352
static void DeserializeTuple(StringInfo key,
360-
StringInfo value,
353+
StringInfo val,
361354
TupleTableSlot *tupleSlot) {
362355

363356
Datum *values = tupleSlot->tts_values;
@@ -376,7 +369,7 @@ static void DeserializeTuple(StringInfo key,
376369
enlargeStringInfo(buffer, bufLen);
377370
buffer->len = bufLen;
378371

379-
memcpy(buffer->data, value->data, bufLen);
372+
memcpy(buffer->data, val->data, bufLen);
380373

381374
for (uint32 index = 1; index < count; index++) {
382375

@@ -407,7 +400,7 @@ static void DeserializeTuple(StringInfo key,
407400
if (index == 0) {
408401
offset = bufLen;
409402
}
410-
current = value->data + offset;
403+
current = val->data + offset;
411404
}
412405
}
413406

@@ -455,20 +448,18 @@ static TupleTableSlot *IterateForeignScan(ForeignScanState *scanState) {
455448
found = GetRequest(relationId, ptr, k, kLen, &v, &vLen);
456449
readState->done = true;
457450
}
458-
/*} else if (readState->isRangeQueryUsed)
459-
{*/
460-
451+
/*} else if (readState->isRangeQueryUsed) {*/
461452
} else {
462453
found = NextRequest(relationId, ptr, &k, &kLen, &v, &vLen);
463454
}
464455

465456
if (found) {
466457
StringInfo key = makeStringInfo();
467458
appendBinaryStringInfo(key, k, kLen);
468-
StringInfo value = makeStringInfo();
469-
appendBinaryStringInfo(value, v, vLen);
459+
StringInfo val = makeStringInfo();
460+
appendBinaryStringInfo(val, v, vLen);
470461

471-
DeserializeTuple(key, value, tupleSlot);
462+
DeserializeTuple(key, val, tupleSlot);
472463

473464
ExecStoreVirtualTuple(tupleSlot);
474465
}
@@ -665,7 +656,7 @@ static void BeginForeignModify(ModifyTableState *modifyTableState,
665656
}
666657

667658
static void SerializeTuple(StringInfo key,
668-
StringInfo value,
659+
StringInfo val,
669660
TupleTableSlot *tupleSlot) {
670661

671662
TupleDesc tupleDescriptor = tupleSlot->tts_tupleDescriptor;
@@ -679,7 +670,7 @@ static void SerializeTuple(StringInfo key,
679670
nulls->len = nullsLen;
680671
memset(nulls->data, 0, nullsLen);
681672

682-
value->len += nullsLen;
673+
val->len += nullsLen;
683674

684675
for (uint32 index = 0; index < count; index++) {
685676

@@ -695,10 +686,10 @@ static void SerializeTuple(StringInfo key,
695686
}
696687

697688
Datum datum = tupleSlot->tts_values[index];
698-
SerializeAttribute(tupleDescriptor, index, datum, index==0? key: value);
689+
SerializeAttribute(tupleDescriptor, index, datum, index==0? key: val);
699690
}
700691

701-
memcpy(value->data, nulls->data, nullsLen);
692+
memcpy(val->data, nulls->data, nullsLen);
702693
}
703694

704695
static TupleTableSlot *ExecForeignInsert(EState *executorState,
@@ -744,13 +735,13 @@ static TupleTableSlot *ExecForeignInsert(EState *executorState,
744735
slot_getallattrs(tupleSlot);
745736

746737
StringInfo key = makeStringInfo();
747-
StringInfo value = makeStringInfo();
738+
StringInfo val = makeStringInfo();
748739

749-
SerializeTuple(key, value, tupleSlot);
740+
SerializeTuple(key, val, tupleSlot);
750741

751742
Relation relation = relationInfo->ri_RelationDesc;
752743
Oid foreignTableId = RelationGetRelid(relation);
753-
PutRequest(foreignTableId, ptr, key->data, key->len, value->data, value->len);
744+
PutRequest(foreignTableId, ptr, key->data, key->len, val->data, val->len);
754745

755746
return tupleSlot;
756747
}
@@ -798,13 +789,13 @@ static TupleTableSlot *ExecForeignUpdate(EState *executorState,
798789
slot_getallattrs(tupleSlot);
799790

800791
StringInfo key = makeStringInfo();
801-
StringInfo value = makeStringInfo();
792+
StringInfo val = makeStringInfo();
802793

803-
SerializeTuple(key, value, tupleSlot);
794+
SerializeTuple(key, val, tupleSlot);
804795

805796
Relation relation = relationInfo->ri_RelationDesc;
806797
Oid foreignTableId = RelationGetRelid(relation);
807-
PutRequest(foreignTableId, ptr, key->data, key->len, value->data, value->len);
798+
PutRequest(foreignTableId, ptr, key->data, key->len, val->data, val->len);
808799

809800
return tupleSlot;
810801
}
@@ -851,9 +842,9 @@ static TupleTableSlot *ExecForeignDelete(EState *executorState,
851842
slot_getallattrs(planSlot);
852843

853844
StringInfo key = makeStringInfo();
854-
StringInfo value = makeStringInfo();
845+
StringInfo val = makeStringInfo();
855846

856-
SerializeTuple(key, value, planSlot);
847+
SerializeTuple(key, val, planSlot);
857848

858849
Relation relation = relationInfo->ri_RelationDesc;
859850
Oid foreignTableId = RelationGetRelid(relation);
@@ -862,7 +853,8 @@ static TupleTableSlot *ExecForeignDelete(EState *executorState,
862853
return tupleSlot;
863854
}
864855

865-
static void EndForeignModify(EState *executorState, ResultRelInfo *relationInfo) {
856+
static void EndForeignModify(EState *executorState,
857+
ResultRelInfo *relationInfo) {
866858
printf("\n-----------------%s----------------------\n", __func__);
867859
/*
868860
* End the table update and release resources. It is normally not

src/kv_fdw.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef KV_FDW_H_
33
#define KV_FDW_H_
44

5+
56
#include "kv_storage.h"
67

78
#include <stdbool.h>
@@ -108,9 +109,9 @@ typedef enum FuncName {
108109
GET,
109110
PUT,
110111
DELETE,
111-
#ifdef VidarDB
112+
#ifdef VidarDB
112113
RANGEQUERY,
113-
#endif
114+
#endif
114115
TERMINATE
115116
} FuncName;
116117

src/kv_shm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ static void KVWorkerMain(int argc, char *argv[]) {
328328
case DELETE:
329329
DeleteResponse(buf + sizeof(responseId));
330330
break;
331-
#ifdef VidarDB
331+
#ifdef VidarDB
332332
case RANGEQUERY:
333333
RangeQueryResponse(buff + sizeof(int));
334-
#endif
334+
#endif
335335
default:
336336
ereport(ERROR, (errmsg("%s failed in switch", __func__)));
337337
}
@@ -431,7 +431,7 @@ static void OpenResponse(char *area) {
431431
char *pos = strrchr(path, '/');
432432
Oid relationId = atoi(pos + 1);
433433
bool found;
434-
434+
435435
KVHashEntry *entry = hash_search(kvTableHash, &relationId, HASH_ENTER, &found);
436436
if (!found) {
437437
entry->relationId = relationId;

src/kv_utility.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ Datum kv_ddl_event_end_trigger(PG_FUNCTION_ARGS) {
187187
}
188188
} else if (nodeTag(parseTree) == T_CreateForeignTableStmt) {
189189
CreateForeignTableStmt *tableStmt = (CreateForeignTableStmt *) parseTree;
190-
ForeignServer *server = GetForeignServerByName(tableStmt->servername, false);
190+
ForeignServer *server = GetForeignServerByName(tableStmt->servername,
191+
false);
191192
if (KVServer(server)) {
192193
Oid relationId = RangeVarGetRelid(tableStmt->base.relation,
193194
AccessShareLock,
@@ -202,7 +203,7 @@ Datum kv_ddl_event_end_trigger(PG_FUNCTION_ARGS) {
202203
* directory for it during database creation time.
203204
*/
204205
KVCreateDatabaseDirectory(MyDatabaseId);
205-
206+
206207
StringInfo kvPath = makeStringInfo();
207208
appendStringInfo(kvPath,
208209
"%s/%s/%u/%u",
@@ -341,7 +342,9 @@ static bool KVCopyTableStatement(CopyStmt* copyStmt) {
341342
return false;
342343
}
343344

344-
Oid relationId = RangeVarGetRelid(copyStmt->relation, AccessShareLock, true);
345+
Oid relationId = RangeVarGetRelid(copyStmt->relation,
346+
AccessShareLock,
347+
true);
345348
return KVTable(relationId);
346349
}
347350

@@ -472,9 +475,6 @@ static uint64 KVCopyIntoTable(const CopyStmt *copyStmt,
472475
ALLOCSET_DEFAULT_SIZES);
473476

474477
Oid relationId = RelationGetRelid(relation);
475-
//KVFdwOptions *fdwOptions = KVGetOptions(relationId);
476-
477-
//void *db = Open(fdwOptions->filename);
478478
ptr = OpenRequest(relationId, ptr);
479479

480480
TupleDesc tupleDescriptor = RelationGetDescr(relation);
@@ -498,8 +498,8 @@ static uint64 KVCopyIntoTable(const CopyStmt *copyStmt,
498498
if (found) {
499499
memset(buffer->data, 0, bufLen);
500500
StringInfo key = makeStringInfo();
501-
StringInfo value = makeStringInfo();
502-
value->len += bufLen;
501+
StringInfo val = makeStringInfo();
502+
val->len += bufLen;
503503

504504
for (uint32 index = 0; index < count; index++) {
505505

@@ -514,16 +514,14 @@ static uint64 KVCopyIntoTable(const CopyStmt *copyStmt,
514514
continue;
515515
}
516516
Datum datum = values[index];
517-
SerializeAttribute(tupleDescriptor, index, datum, index==0? key: value);
517+
SerializeAttribute(tupleDescriptor,
518+
index,
519+
datum,
520+
index==0? key: val);
518521
}
519-
memcpy(value->data, buffer->data, bufLen);
520-
521-
//if (!Put(db, key->data, key->len, value->data, value->len)) {
522-
// ereport(ERROR, (errmsg("error from Copy")));
523-
//}
522+
memcpy(val->data, buffer->data, bufLen);
524523

525-
526-
PutRequest(relationId, ptr, key->data, key->len, value->data, value->len);
524+
PutRequest(relationId, ptr, key->data, key->len, val->data, val->len);
527525
rowCount++;
528526
}
529527

@@ -534,7 +532,6 @@ static uint64 KVCopyIntoTable(const CopyStmt *copyStmt,
534532

535533
/* end read/write sessions and close the relation */
536534
EndCopyFrom(copyState);
537-
//Close(db);
538535
CloseRequest(relationId, ptr);
539536
heap_close(relation, ShareUpdateExclusiveLock);
540537

@@ -665,7 +662,7 @@ static void KVProcessUtility(PlannedStmt *plannedStmt,
665662

666663
CopyStmt *copyStmt = (CopyStmt *) parseTree;
667664
if (KVCopyTableStatement(copyStmt)) {
668-
665+
669666
uint64 rowCount = 0;
670667
if (copyStmt->is_from) {
671668
rowCount = KVCopyIntoTable(copyStmt, queryString);

0 commit comments

Comments
 (0)