94
94
*/
95
95
typedef struct TapeBlockTrailer
96
96
{
97
- long prev ; /* previous block on this tape, or -1 on first
97
+ int64 prev ; /* previous block on this tape, or -1 on first
98
98
* block */
99
- long next ; /* next block on this tape, or # of valid
99
+ int64 next ; /* next block on this tape, or # of valid
100
100
* bytes on last block (if < 0) */
101
101
} TapeBlockTrailer ;
102
102
@@ -153,10 +153,10 @@ struct LogicalTape
153
153
* When concatenation of worker tape BufFiles is performed, an offset to
154
154
* the first block in the unified BufFile space is applied during reads.
155
155
*/
156
- long firstBlockNumber ;
157
- long curBlockNumber ;
158
- long nextBlockNumber ;
159
- long offsetBlockNumber ;
156
+ int64 firstBlockNumber ;
157
+ int64 curBlockNumber ;
158
+ int64 nextBlockNumber ;
159
+ int64 offsetBlockNumber ;
160
160
161
161
/*
162
162
* Buffer for current data block(s).
@@ -172,7 +172,7 @@ struct LogicalTape
172
172
* order; blocks are consumed from the end of the array (lowest block
173
173
* numbers first).
174
174
*/
175
- long * prealloc ;
175
+ int64 * prealloc ;
176
176
int nprealloc ; /* number of elements in list */
177
177
int prealloc_size ; /* number of elements list can hold */
178
178
};
@@ -200,9 +200,9 @@ struct LogicalTapeSet
200
200
* blocks that are in unused holes between worker spaces following BufFile
201
201
* concatenation.
202
202
*/
203
- long nBlocksAllocated ; /* # of blocks allocated */
204
- long nBlocksWritten ; /* # of blocks used in underlying file */
205
- long nHoleBlocks ; /* # of "hole" blocks left */
203
+ int64 nBlocksAllocated ; /* # of blocks allocated */
204
+ int64 nBlocksWritten ; /* # of blocks used in underlying file */
205
+ int64 nHoleBlocks ; /* # of "hole" blocks left */
206
206
207
207
/*
208
208
* We store the numbers of recycled-and-available blocks in freeBlocks[].
@@ -213,19 +213,19 @@ struct LogicalTapeSet
213
213
* LogicalTapeSetForgetFreeSpace().
214
214
*/
215
215
bool forgetFreeSpace ; /* are we remembering free blocks? */
216
- long * freeBlocks ; /* resizable array holding minheap */
217
- long nFreeBlocks ; /* # of currently free blocks */
216
+ int64 * freeBlocks ; /* resizable array holding minheap */
217
+ int64 nFreeBlocks ; /* # of currently free blocks */
218
218
Size freeBlocksLen ; /* current allocated length of freeBlocks[] */
219
219
bool enable_prealloc ; /* preallocate write blocks? */
220
220
};
221
221
222
222
static LogicalTape * ltsCreateTape (LogicalTapeSet * lts );
223
- static void ltsWriteBlock (LogicalTapeSet * lts , long blocknum , const void * buffer );
224
- static void ltsReadBlock (LogicalTapeSet * lts , long blocknum , void * buffer );
225
- static long ltsGetBlock (LogicalTapeSet * lts , LogicalTape * lt );
226
- static long ltsGetFreeBlock (LogicalTapeSet * lts );
227
- static long ltsGetPreallocBlock (LogicalTapeSet * lts , LogicalTape * lt );
228
- static void ltsReleaseBlock (LogicalTapeSet * lts , long blocknum );
223
+ static void ltsWriteBlock (LogicalTapeSet * lts , int64 blocknum , const void * buffer );
224
+ static void ltsReadBlock (LogicalTapeSet * lts , int64 blocknum , void * buffer );
225
+ static int64 ltsGetBlock (LogicalTapeSet * lts , LogicalTape * lt );
226
+ static int64 ltsGetFreeBlock (LogicalTapeSet * lts );
227
+ static int64 ltsGetPreallocBlock (LogicalTapeSet * lts , LogicalTape * lt );
228
+ static void ltsReleaseBlock (LogicalTapeSet * lts , int64 blocknum );
229
229
static void ltsInitReadBuffer (LogicalTape * lt );
230
230
231
231
@@ -235,7 +235,7 @@ static void ltsInitReadBuffer(LogicalTape *lt);
235
235
* No need for an error return convention; we ereport() on any error.
236
236
*/
237
237
static void
238
- ltsWriteBlock (LogicalTapeSet * lts , long blocknum , const void * buffer )
238
+ ltsWriteBlock (LogicalTapeSet * lts , int64 blocknum , const void * buffer )
239
239
{
240
240
/*
241
241
* BufFile does not support "holes", so if we're about to write a block
@@ -263,8 +263,8 @@ ltsWriteBlock(LogicalTapeSet *lts, long blocknum, const void *buffer)
263
263
if (BufFileSeekBlock (lts -> pfile , blocknum ) != 0 )
264
264
ereport (ERROR ,
265
265
(errcode_for_file_access (),
266
- errmsg ("could not seek to block %ld of temporary file" ,
267
- blocknum )));
266
+ errmsg ("could not seek to block %lld of temporary file" ,
267
+ ( long long ) blocknum )));
268
268
BufFileWrite (lts -> pfile , buffer , BLCKSZ );
269
269
270
270
/* Update nBlocksWritten, if we extended the file */
@@ -279,13 +279,13 @@ ltsWriteBlock(LogicalTapeSet *lts, long blocknum, const void *buffer)
279
279
* module should never attempt to read a block it doesn't know is there.
280
280
*/
281
281
static void
282
- ltsReadBlock (LogicalTapeSet * lts , long blocknum , void * buffer )
282
+ ltsReadBlock (LogicalTapeSet * lts , int64 blocknum , void * buffer )
283
283
{
284
284
if (BufFileSeekBlock (lts -> pfile , blocknum ) != 0 )
285
285
ereport (ERROR ,
286
286
(errcode_for_file_access (),
287
- errmsg ("could not seek to block %ld of temporary file" ,
288
- blocknum )));
287
+ errmsg ("could not seek to block %lld of temporary file" ,
288
+ ( long long ) blocknum )));
289
289
BufFileReadExact (lts -> pfile , buffer , BLCKSZ );
290
290
}
291
291
@@ -303,7 +303,7 @@ ltsReadFillBuffer(LogicalTape *lt)
303
303
do
304
304
{
305
305
char * thisbuf = lt -> buffer + lt -> nbytes ;
306
- long datablocknum = lt -> nextBlockNumber ;
306
+ int64 datablocknum = lt -> nextBlockNumber ;
307
307
308
308
/* Fetch next block number */
309
309
if (datablocknum == -1L )
@@ -333,28 +333,28 @@ ltsReadFillBuffer(LogicalTape *lt)
333
333
return (lt -> nbytes > 0 );
334
334
}
335
335
336
- static inline unsigned long
337
- left_offset (unsigned long i )
336
+ static inline uint64
337
+ left_offset (uint64 i )
338
338
{
339
339
return 2 * i + 1 ;
340
340
}
341
341
342
- static inline unsigned long
343
- right_offset (unsigned long i )
342
+ static inline uint64
343
+ right_offset (uint64 i )
344
344
{
345
345
return 2 * i + 2 ;
346
346
}
347
347
348
- static inline unsigned long
349
- parent_offset (unsigned long i )
348
+ static inline uint64
349
+ parent_offset (uint64 i )
350
350
{
351
351
return (i - 1 ) / 2 ;
352
352
}
353
353
354
354
/*
355
355
* Get the next block for writing.
356
356
*/
357
- static long
357
+ static int64
358
358
ltsGetBlock (LogicalTapeSet * lts , LogicalTape * lt )
359
359
{
360
360
if (lts -> enable_prealloc )
@@ -367,14 +367,14 @@ ltsGetBlock(LogicalTapeSet *lts, LogicalTape *lt)
367
367
* Select the lowest currently unused block from the tape set's global free
368
368
* list min heap.
369
369
*/
370
- static long
370
+ static int64
371
371
ltsGetFreeBlock (LogicalTapeSet * lts )
372
372
{
373
- long * heap = lts -> freeBlocks ;
374
- long blocknum ;
375
- long heapsize ;
376
- long holeval ;
377
- unsigned long holepos ;
373
+ int64 * heap = lts -> freeBlocks ;
374
+ int64 blocknum ;
375
+ int64 heapsize ;
376
+ int64 holeval ;
377
+ uint64 holepos ;
378
378
379
379
/* freelist empty; allocate a new block */
380
380
if (lts -> nFreeBlocks == 0 )
@@ -398,9 +398,9 @@ ltsGetFreeBlock(LogicalTapeSet *lts)
398
398
heapsize = lts -> nFreeBlocks ;
399
399
while (true)
400
400
{
401
- unsigned long left = left_offset (holepos );
402
- unsigned long right = right_offset (holepos );
403
- unsigned long min_child ;
401
+ uint64 left = left_offset (holepos );
402
+ uint64 right = right_offset (holepos );
403
+ uint64 min_child ;
404
404
405
405
if (left < heapsize && right < heapsize )
406
406
min_child = (heap [left ] < heap [right ]) ? left : right ;
@@ -427,7 +427,7 @@ ltsGetFreeBlock(LogicalTapeSet *lts)
427
427
* Refill the preallocation list with blocks from the tape set's free list if
428
428
* necessary.
429
429
*/
430
- static long
430
+ static int64
431
431
ltsGetPreallocBlock (LogicalTapeSet * lts , LogicalTape * lt )
432
432
{
433
433
/* sorted in descending order, so return the last element */
@@ -437,16 +437,16 @@ ltsGetPreallocBlock(LogicalTapeSet *lts, LogicalTape *lt)
437
437
if (lt -> prealloc == NULL )
438
438
{
439
439
lt -> prealloc_size = TAPE_WRITE_PREALLOC_MIN ;
440
- lt -> prealloc = (long * ) palloc (sizeof (long ) * lt -> prealloc_size );
440
+ lt -> prealloc = (int64 * ) palloc (sizeof (int64 ) * lt -> prealloc_size );
441
441
}
442
442
else if (lt -> prealloc_size < TAPE_WRITE_PREALLOC_MAX )
443
443
{
444
444
/* when the preallocation list runs out, double the size */
445
445
lt -> prealloc_size *= 2 ;
446
446
if (lt -> prealloc_size > TAPE_WRITE_PREALLOC_MAX )
447
447
lt -> prealloc_size = TAPE_WRITE_PREALLOC_MAX ;
448
- lt -> prealloc = (long * ) repalloc (lt -> prealloc ,
449
- sizeof (long ) * lt -> prealloc_size );
448
+ lt -> prealloc = (int64 * ) repalloc (lt -> prealloc ,
449
+ sizeof (int64 ) * lt -> prealloc_size );
450
450
}
451
451
452
452
/* refill preallocation list */
@@ -466,10 +466,10 @@ ltsGetPreallocBlock(LogicalTapeSet *lts, LogicalTape *lt)
466
466
* Return a block# to the freelist.
467
467
*/
468
468
static void
469
- ltsReleaseBlock (LogicalTapeSet * lts , long blocknum )
469
+ ltsReleaseBlock (LogicalTapeSet * lts , int64 blocknum )
470
470
{
471
- long * heap ;
472
- unsigned long holepos ;
471
+ int64 * heap ;
472
+ uint64 holepos ;
473
473
474
474
/*
475
475
* Do nothing if we're no longer interested in remembering free space.
@@ -486,12 +486,12 @@ ltsReleaseBlock(LogicalTapeSet *lts, long blocknum)
486
486
* If the freelist becomes very large, just return and leak this free
487
487
* block.
488
488
*/
489
- if (lts -> freeBlocksLen * 2 * sizeof (long ) > MaxAllocSize )
489
+ if (lts -> freeBlocksLen * 2 * sizeof (int64 ) > MaxAllocSize )
490
490
return ;
491
491
492
492
lts -> freeBlocksLen *= 2 ;
493
- lts -> freeBlocks = (long * ) repalloc (lts -> freeBlocks ,
494
- lts -> freeBlocksLen * sizeof (long ));
493
+ lts -> freeBlocks = (int64 * ) repalloc (lts -> freeBlocks ,
494
+ lts -> freeBlocksLen * sizeof (int64 ));
495
495
}
496
496
497
497
/* create a "hole" at end of minheap array */
@@ -502,7 +502,7 @@ ltsReleaseBlock(LogicalTapeSet *lts, long blocknum)
502
502
/* sift up to insert blocknum */
503
503
while (holepos != 0 )
504
504
{
505
- unsigned long parent = parent_offset (holepos );
505
+ uint64 parent = parent_offset (holepos );
506
506
507
507
if (heap [parent ] < blocknum )
508
508
break ;
@@ -566,7 +566,7 @@ LogicalTapeSetCreate(bool preallocate, SharedFileSet *fileset, int worker)
566
566
lts -> nHoleBlocks = 0L ;
567
567
lts -> forgetFreeSpace = false;
568
568
lts -> freeBlocksLen = 32 ; /* reasonable initial guess */
569
- lts -> freeBlocks = (long * ) palloc (lts -> freeBlocksLen * sizeof (long ));
569
+ lts -> freeBlocks = (int64 * ) palloc (lts -> freeBlocksLen * sizeof (int64 ));
570
570
lts -> nFreeBlocks = 0 ;
571
571
lts -> enable_prealloc = preallocate ;
572
572
@@ -609,7 +609,7 @@ LogicalTape *
609
609
LogicalTapeImport (LogicalTapeSet * lts , int worker , TapeShare * shared )
610
610
{
611
611
LogicalTape * lt ;
612
- long tapeblocks ;
612
+ int64 tapeblocks ;
613
613
char filename [MAXPGPATH ];
614
614
BufFile * file ;
615
615
int64 filesize ;
@@ -789,7 +789,7 @@ LogicalTapeWrite(LogicalTape *lt, const void *ptr, size_t size)
789
789
if (lt -> pos >= (int ) TapeBlockPayloadSize )
790
790
{
791
791
/* Buffer full, dump it out */
792
- long nextBlockNumber ;
792
+ int64 nextBlockNumber ;
793
793
794
794
if (!lt -> dirty )
795
795
{
@@ -1086,7 +1086,7 @@ LogicalTapeBackspace(LogicalTape *lt, size_t size)
1086
1086
seekpos = (size_t ) lt -> pos ; /* part within this block */
1087
1087
while (size > seekpos )
1088
1088
{
1089
- long prev = TapeBlockGetTrailer (lt -> buffer )-> prev ;
1089
+ int64 prev = TapeBlockGetTrailer (lt -> buffer )-> prev ;
1090
1090
1091
1091
if (prev == -1L )
1092
1092
{
@@ -1100,10 +1100,10 @@ LogicalTapeBackspace(LogicalTape *lt, size_t size)
1100
1100
ltsReadBlock (lt -> tapeSet , prev , lt -> buffer );
1101
1101
1102
1102
if (TapeBlockGetTrailer (lt -> buffer )-> next != lt -> curBlockNumber )
1103
- elog (ERROR , "broken tape, next of block %ld is %ld , expected %ld " ,
1104
- prev ,
1105
- TapeBlockGetTrailer (lt -> buffer )-> next ,
1106
- lt -> curBlockNumber );
1103
+ elog (ERROR , "broken tape, next of block %lld is %lld , expected %lld " ,
1104
+ ( long long ) prev ,
1105
+ ( long long ) ( TapeBlockGetTrailer (lt -> buffer )-> next ) ,
1106
+ ( long long ) lt -> curBlockNumber );
1107
1107
1108
1108
lt -> nbytes = TapeBlockPayloadSize ;
1109
1109
lt -> curBlockNumber = prev ;
@@ -1130,7 +1130,7 @@ LogicalTapeBackspace(LogicalTape *lt, size_t size)
1130
1130
* LogicalTapeTell().
1131
1131
*/
1132
1132
void
1133
- LogicalTapeSeek (LogicalTape * lt , long blocknum , int offset )
1133
+ LogicalTapeSeek (LogicalTape * lt , int64 blocknum , int offset )
1134
1134
{
1135
1135
Assert (lt -> frozen );
1136
1136
Assert (offset >= 0 && offset <= TapeBlockPayloadSize );
@@ -1159,7 +1159,7 @@ LogicalTapeSeek(LogicalTape *lt, long blocknum, int offset)
1159
1159
* the position for a seek after freezing. Not clear if anyone needs that.
1160
1160
*/
1161
1161
void
1162
- LogicalTapeTell (LogicalTape * lt , long * blocknum , int * offset )
1162
+ LogicalTapeTell (LogicalTape * lt , int64 * blocknum , int * offset )
1163
1163
{
1164
1164
if (lt -> buffer == NULL )
1165
1165
ltsInitReadBuffer (lt );
@@ -1179,7 +1179,7 @@ LogicalTapeTell(LogicalTape *lt, long *blocknum, int *offset)
1179
1179
* This should not be called while there are open write buffers; otherwise it
1180
1180
* may not account for buffered data.
1181
1181
*/
1182
- long
1182
+ int64
1183
1183
LogicalTapeSetBlocks (LogicalTapeSet * lts )
1184
1184
{
1185
1185
return lts -> nBlocksWritten - lts -> nHoleBlocks ;
0 commit comments