Skip to content

Commit eb00f1d

Browse files
committed
Refactor pg_rewind for more clear decision making.
Deciding what to do with each file is now a separate step after all the necessary information has been gathered. It is more clear that way. Previously, the decision-making was divided between process_source_file() and process_target_file(), and it was a bit hard to piece together what the overall rules were. Reviewed-by: Kyotaro Horiguchi, Soumyadeep Chakraborty Discussion: https://www.postgresql.org/message-id/0c5b3783-af52-3ee5-f8fa-6e794061f70d%40iki.fi
1 parent ffb4e27 commit eb00f1d

File tree

7 files changed

+386
-314
lines changed

7 files changed

+386
-314
lines changed

src/bin/pg_rewind/copy_fetch.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ copy_executeFileMap(filemap_t *map)
210210
for (i = 0; i < map->narray; i++)
211211
{
212212
entry = map->array[i];
213-
execute_pagemap(&entry->pagemap, entry->path);
213+
execute_pagemap(&entry->target_pages_to_overwrite, entry->path);
214214

215215
switch (entry->action)
216216
{
@@ -219,16 +219,16 @@ copy_executeFileMap(filemap_t *map)
219219
break;
220220

221221
case FILE_ACTION_COPY:
222-
rewind_copy_file_range(entry->path, 0, entry->newsize, true);
222+
rewind_copy_file_range(entry->path, 0, entry->source_size, true);
223223
break;
224224

225225
case FILE_ACTION_TRUNCATE:
226-
truncate_target_file(entry->path, entry->newsize);
226+
truncate_target_file(entry->path, entry->source_size);
227227
break;
228228

229229
case FILE_ACTION_COPY_TAIL:
230-
rewind_copy_file_range(entry->path, entry->oldsize,
231-
entry->newsize, false);
230+
rewind_copy_file_range(entry->path, entry->target_size,
231+
entry->source_size, false);
232232
break;
233233

234234
case FILE_ACTION_CREATE:
@@ -238,6 +238,10 @@ copy_executeFileMap(filemap_t *map)
238238
case FILE_ACTION_REMOVE:
239239
remove_target(entry);
240240
break;
241+
242+
case FILE_ACTION_UNDECIDED:
243+
pg_fatal("no action decided for \"%s\"", entry->path);
244+
break;
241245
}
242246
}
243247

src/bin/pg_rewind/file_ops.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ void
126126
remove_target(file_entry_t *entry)
127127
{
128128
Assert(entry->action == FILE_ACTION_REMOVE);
129+
Assert(entry->target_exists);
129130

130-
switch (entry->type)
131+
switch (entry->target_type)
131132
{
132133
case FILE_TYPE_DIRECTORY:
133134
remove_target_dir(entry->path);
@@ -140,28 +141,37 @@ remove_target(file_entry_t *entry)
140141
case FILE_TYPE_SYMLINK:
141142
remove_target_symlink(entry->path);
142143
break;
144+
145+
case FILE_TYPE_UNDEFINED:
146+
pg_fatal("undefined file type for \"%s\"", entry->path);
147+
break;
143148
}
144149
}
145150

146151
void
147152
create_target(file_entry_t *entry)
148153
{
149154
Assert(entry->action == FILE_ACTION_CREATE);
155+
Assert(!entry->target_exists);
150156

151-
switch (entry->type)
157+
switch (entry->source_type)
152158
{
153159
case FILE_TYPE_DIRECTORY:
154160
create_target_dir(entry->path);
155161
break;
156162

157163
case FILE_TYPE_SYMLINK:
158-
create_target_symlink(entry->path, entry->link_target);
164+
create_target_symlink(entry->path, entry->source_link_target);
159165
break;
160166

161167
case FILE_TYPE_REGULAR:
162168
/* can't happen. Regular files are created with open_target_file. */
163169
pg_fatal("invalid action (CREATE) for regular file");
164170
break;
171+
172+
case FILE_TYPE_UNDEFINED:
173+
pg_fatal("undefined file type for \"%s\"", entry->path);
174+
break;
165175
}
166176
}
167177

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy