PostgreSQL Source Code: src/backend/storage/file/reinit.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

16

18

26

28 int op);

30 int op);

31

32typedef struct

33{

36

37

38

39

40

41

42

43

44

45

46void

48{

50 DIR *spc_dir;

51 struct dirent *spc_de;

53 oldctx;

54

55

56 elog(DEBUG1, "resetting unlogged relations: cleanup %d init %d",

59

60

61

62

63

65 "ResetUnloggedRelations",

68

69

71

72

73

74

76

77

78

79

81

83 {

84 if (strcmp(spc_de->d_name, ".") == 0 ||

85 strcmp(spc_de->d_name, "..") == 0)

86 continue;

87

88 snprintf(temp_path, sizeof(temp_path), "%s/%s/%s",

91 }

92

94

95

96

97

100}

101

102

103

104

105static void

107{

108 DIR *ts_dir;

110 char dbspace_path[MAXPGPATH * 2];

111

113

114

115

116

117

118

119

120

121

122 if (ts_dir == NULL && errno == ENOENT)

123 {

126 errmsg("could not open directory \"%s\": %m",

127 tsdirname)));

128 return;

129 }

130

131 while ((de = ReadDir(ts_dir, tsdirname)) != NULL)

132 {

133

134

135

136

137

138 if (strspn(de->d_name, "0123456789") != strlen(de->d_name))

139 continue;

140

141 snprintf(dbspace_path, sizeof(dbspace_path), "%s/%s",

142 tsdirname, de->d_name);

143

145 ereport_startup_progress("resetting unlogged relations (init), elapsed time: %ld.%02d s, current path: %s",

146 dbspace_path);

148 ereport_startup_progress("resetting unlogged relations (cleanup), elapsed time: %ld.%02d s, current path: %s",

149 dbspace_path);

150

152 }

153

155}

156

157

158

159

160static void

162{

163 DIR *dbspace_dir;

166

167

169

170

171

172

173

174

176 {

179

180

181

182

183

184

185

186

187 ctl.keysize = sizeof(Oid);

192

193

194 dbspace_dir = AllocateDir(dbspacedirname);

195 while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)

196 {

198 unsigned segno;

200

201

204 &forkNum, &segno))

205 continue;

206

207

209 continue;

210

211

212

213

215 }

216

217

219

220

221

222

223

225 {

227 return;

228 }

229

230

231

232

233 dbspace_dir = AllocateDir(dbspacedirname);

234 while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)

235 {

237 unsigned segno;

239

240

243 &forkNum, &segno))

244 continue;

245

246

248 continue;

249

250

251

252

253

255 {

256 snprintf(rm_path, sizeof(rm_path), "%s/%s",

257 dbspacedirname, de->d_name);

258 if (unlink(rm_path) < 0)

261 errmsg("could not remove file \"%s\": %m",

262 rm_path)));

263 else

264 elog(DEBUG2, "unlinked file \"%s\"", rm_path);

265 }

266 }

267

268

271 }

272

273

274

275

276

277

278

279

281 {

282

283 dbspace_dir = AllocateDir(dbspacedirname);

284 while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)

285 {

288 unsigned segno;

291

292

294 &forkNum, &segno))

295 continue;

296

297

299 continue;

300

301

302 snprintf(srcpath, sizeof(srcpath), "%s/%s",

303 dbspacedirname, de->d_name);

304

305

306 if (segno == 0)

308 dbspacedirname, relNumber);

309 else

311 dbspacedirname, relNumber, segno);

312

313

316 }

317

319

320

321

322

323

324

325

326

327 dbspace_dir = AllocateDir(dbspacedirname);

328 while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)

329 {

332 unsigned segno;

334

335

337 &forkNum, &segno))

338 continue;

339

340

342 continue;

343

344

345 if (segno == 0)

346 snprintf(mainpath, sizeof(mainpath), "%s/%u",

347 dbspacedirname, relNumber);

348 else

349 snprintf(mainpath, sizeof(mainpath), "%s/%u.%u",

350 dbspacedirname, relNumber, segno);

351

353 }

354

356

357

358

359

360

361

362

363

364

366 }

367}

368

369

370

371

372

373

374

375

376

377

378

379bool

382{

383 unsigned long n,

384 s;

386 char *endp;

387

390 *segno = 0;

391

392

393

394

395

396

397

398

399

400

401

402 if (name[0] < '1' || name[0] > '9')

403 return false;

404

405

406

407

408

409 errno = 0;

410 n = strtoul(name, &endp, 10);

412 return false;

414

415

416 if (*name != '_')

418 else

419 {

420 int forkchar;

421

423 if (forkchar <= 0)

424 return false;

425 name += forkchar + 1;

426 }

427

428

429 if (*name != '.')

430 s = 0;

431 else

432 {

433

434 if (name[1] < '1' || name[1] > '9')

435 return false;

436

437 errno = 0;

438 s = strtoul(name + 1, &endp, 10);

440 return false;

442 }

443

444

445 if (*name != '\0')

446 return false;

447

448

450 *fork = f;

451 *segno = (unsigned) s;

452 return true;

453}

void begin_startup_progress_phase(void)

void copy_file(const char *fromfile, const char *tofile)

void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)

void hash_destroy(HTAB *hashp)

long hash_get_num_entries(HTAB *hashp)

HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)

int errcode_for_file_access(void)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

void fsync_fname(const char *fname, bool isdir)

DIR * AllocateDir(const char *dirname)

struct dirent * ReadDir(DIR *dir, const char *dirname)

static char dstpath[MAXPGPATH]

Assert(PointerIsAligned(start, uint64))

MemoryContext CurrentMemoryContext

void MemoryContextDelete(MemoryContext context)

#define AllocSetContextCreate

#define ALLOCSET_DEFAULT_SIZES

static MemoryContext MemoryContextSwitchTo(MemoryContext context)

static unsigned hash(unsigned *uv, int n)

static void ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)

void ResetUnloggedRelations(int op)

bool parse_filename_for_nontemp_relation(const char *name, RelFileNumber *relnumber, ForkNumber *fork, unsigned *segno)

static void ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)

#define UNLOGGED_RELATION_INIT

#define UNLOGGED_RELATION_CLEANUP

int forkname_chars(const char *str, ForkNumber *fork)

#define InvalidRelFileNumber

#define TABLESPACE_VERSION_DIRECTORY

#define ereport_startup_progress(msg,...)