Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3491b43

Browse files
committed
Add lock free algorithm for load balancing.
1 parent6ce7163 commit3491b43

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

‎backup.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
315315
{
316316
total_files_num++;
317317
}
318+
319+
__sync_lock_release(&file->lock);
318320
}
319321

320322
if (num_threads<1)
@@ -329,20 +331,12 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
329331
backup_files_args*arg=pg_malloc(sizeof(backup_files_args));
330332
arg->from_root=pgdata;
331333
arg->to_root=path;
332-
arg->files=parray_new();
334+
arg->files=backup_files_list;
333335
arg->prev_files=prev_files;
334336
arg->lsn=lsn;
335337
backup_threads_args[i]=arg;
336338
}
337339

338-
/* balance load between threads */
339-
for (i=0;i<parray_num(backup_files_list);i++)
340-
{
341-
intcur_thread=i %num_threads;
342-
parray_append(backup_threads_args[cur_thread]->files,
343-
parray_get(backup_files_list,i));
344-
}
345-
346340
total_copy_files_increment=0;
347341

348342
/* Run threads */
@@ -935,6 +929,8 @@ backup_files(void *arg)
935929
structstatbuf;
936930

937931
pgFile*file= (pgFile*)parray_get(arguments->files,i);
932+
if (__sync_lock_test_and_set(&file->lock,1)!=0)
933+
continue;
938934

939935
/* If current time is rewinded, abort this backup. */
940936
if (tv.tv_sec<file->mtime)

‎pg_arman.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ typedef struct pgFile
5656
that the file existed but was not backed up
5757
because not modified since last backup. */
5858
pg_crc32crc;/* CRC value of the file, regular file only */
59-
char*linked;/* path of the linked file */
59+
char*linked;/* path of the linked file */
6060
boolis_datafile;/* true if the file is PostgreSQL data file */
6161
char*path;/* path of the file */
6262
char*ptrack_path;
6363
intsegno;/* Segment number for ptrack */
64+
volatileuint32lock;
6465
datapagemap_tpagemap;
6566
}pgFile;
6667

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp