Revert "优化DSS拷贝文件 + 修改合并冲突"

This reverts commit 2f313a962a8483da97436e3fe41cec39610a8798.
This commit is contained in:
congzhou2603
2025-06-06 09:27:34 +08:00
parent bc25527787
commit 9c0aaa0d64
6 changed files with 59 additions and 54 deletions

View File

@ -2150,6 +2150,8 @@ void initDssPath(char *dssdir)
rc = snprintf_s(g_instance.datadir_cxt.hbaConfigFilePath, MAXPGPATH, MAXPGPATH - 1, "%s/shared_pg_hba.conf",
dssdir);
securec_check_ss(rc, "", "");
ss_initdwsubdir(dssdir);
}
void initDSSConf(void)

View File

@ -12886,57 +12886,69 @@ ErrCode write_guc_file(const char* path, char** lines)
static int copy_file_dss(char *scpath, char *despath)
{
const int buffer_size = 16384;
char buffer[buffer_size];
size_t need_write_size;
FILE *srcFile = fopen(scpath, "rb");
FILE *destFile = NULL;
if (srcFile == NULL) {
ereport(WARNING, (errmsg("could not open source file: %s:%s", scpath, TRANSLATE_ERRNO)));
return -1;
}
if (remove(despath) != 0 && !is_file_delete(errno)) {
ereport(WARNING, (errmsg("could not remove destination file: %s:%s", despath, TRANSLATE_ERRNO)));
fclose(srcFile);
return -1;
}
destFile = fopen(despath, "wb");
if (destFile == NULL) {
ereport(WARNING, (errmsg("could not create destination file: %s:%s", despath, TRANSLATE_ERRNO)));
fclose(srcFile);
return -1;
}
int fd_source, fd_target;
int res = 0;
ssize_t step_size = DSS_BYTE_AGAINST;
ssize_t read_size = DSS_BYTE_AGAINST;
struct stat statbuf;
if (stat(scpath, &statbuf) == 0) {
need_write_size = statbuf.st_size;
} else {
ereport(WARNING, (errmsg("could not stat source file: %s:%s", scpath, TRANSLATE_ERRNO)));
fclose(srcFile);
fclose(destFile);
return -1;
char buffer[step_size];
off_t offset = 0;
if (lstat(despath, &statbuf) == 0) {
if (remove(despath) != 0) {
ereport(LOG, (errmsg("could not remove file: %s", despath)));
return -1;
}
}
if ((fread(buffer, 1, buffer_size, srcFile)) <= 0) {
ereport(WARNING, (errmsg("could not read source file: %s:%s", scpath, TRANSLATE_ERRNO)));
fclose(srcFile);
fclose(destFile);
fd_source = open(scpath, O_RDONLY, 0644);
if (fd_source < 0) {
ereport(LOG, (errmsg("could not open file: %s", scpath)));
return -1;
}
fd_target = open(despath, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd_target < 0) {
ereport(LOG, (errmsg("could not open file: %s", despath)));
close(fd_source);
return -1;
}
int size = lseek(fd_source, 0, SEEK_END);
lseek(fd_source, 0, SEEK_SET);
while (offset < size) {
if (offset + step_size > size) {
read_size = size - offset;
errno_t rc = memset_s(buffer, step_size, ' ', step_size);
securec_check(rc, "\0", "\0");
buffer[read_size] = '\n';
}
res = pread(fd_source, buffer, step_size, offset);
if (res != read_size && res != step_size) {
ereport(LOG, (errmsg("read %s, failed, errno: %s", scpath, strerror(errno))));
close(fd_source);
close(fd_target);
return -1;
}
res = pwrite(fd_target, buffer, step_size, offset);
if (res != step_size) {
ereport(LOG, (errmsg("write %s, failed, errno: %s", despath, strerror(errno))));
close(fd_source);
close(fd_target);
return -1;
}
offset += step_size;
}
res = ftruncate(fd_target, size);
if (res != 0) {
close(fd_source);
close(fd_target);
ereport(LOG, (errmsg("truncate %s, failed, errno: %s", despath, strerror(errno))));
return -1;
}
/* not use read size because of the read size of file in dss is not the same as the file size */
if (fwrite(buffer, 1, need_write_size, destFile) <= 0 ) {
ereport(WARNING, (errmsg("write error to destination file: %s:%s", despath, TRANSLATE_ERRNO)));
fclose(srcFile);
fclose(destFile);
return -1;
}
fclose(srcFile);
fclose(destFile);
close(fd_source);
close(fd_target);
return 0;
}

View File

@ -103,7 +103,6 @@ int dss_device_init(const char *conn_path, bool enable_dss)
SS_RETURN_IFERR(dss_load_symbol(device_op.handle, "dss_fseek", (void **)&device_op.dss_seek));
SS_RETURN_IFERR(dss_load_symbol(device_op.handle, "dss_ftruncate", (void **)&device_op.dss_truncate));
SS_RETURN_IFERR(dss_load_symbol(device_op.handle, "dss_fwrite", (void **)&device_op.dss_write));
SS_RETURN_IFERR(dss_load_symbol(device_op.handle, "dss_fcopy", (void **)&device_op.dss_fcopy));
SS_RETURN_IFERR(dss_load_symbol(device_op.handle, "dss_pwrite", (void **)&device_op.dss_pwrite));
SS_RETURN_IFERR(dss_load_symbol(device_op.handle, "dss_dmake", (void **)&device_op.dss_create_dir));
SS_RETURN_IFERR(dss_load_symbol(device_op.handle, "dss_dopen", (void **)&device_op.dss_open_dir));

View File

@ -851,11 +851,6 @@ int dss_compare_size(const char *vg_name, long long *au_size)
return GS_SUCCESS;
}
int dss_file_copy(const char *src_path, const char *dest_path)
{
return g_dss_device_op.dss_fcopy(src_path, dest_path);
}
int dss_aio_prep_pwrite(void *iocb, int fd, void *buf, size_t count, long long offset)
{
return g_dss_device_op.dss_aio_pwrite(iocb, fd, buf, count, offset);

View File

@ -55,7 +55,6 @@ typedef int (*dss_align_device_size)(int size);
typedef int (*dss_link_device)(const char *oldpath, const char *newpath);
typedef int (*dss_unlink_device)(const char *path);
typedef int (*dss_device_name)(int handle, char *fname, size_t fname_size);
typedef int (*dss_fcopy_device)(const char *src_path, const char *dest_path);
typedef int (*dss_read_device_link)(const char *path, char *buf, int bufsize);
typedef int (*dss_stat_device)(const char *path, dss_stat_info_t item);
typedef int (*dss_lstat_device)(const char *path, dss_stat_info_t item);
@ -94,7 +93,6 @@ typedef struct st_dss_device_op_t {
dss_align_device_size dss_align_size;
dss_device_size dss_fsize;
dss_device_name dss_fname;
dss_fcopy_device dss_fcopy;
dss_error_info dss_get_error;
dss_open_device_dir dss_open_dir;
dss_read_device_dir dss_read_dir;

View File

@ -78,7 +78,6 @@ int dss_remove_dev(const char *name);
int dss_get_addr(int handle, long long offset, char *poolname, char *imagename, char *objAddr,
unsigned int *objId, unsigned long int *objOffset);
int dss_compare_size(const char *vg_name, long long *au_size);
int dss_file_copy(const char *src_path, const char *dest_path);
int dss_aio_prep_pwrite(void *iocb, int fd, void *buf, size_t count, long long offset);
int dss_aio_prep_pread(void *iocb, int fd, void *buf, size_t count, long long offset);
int dss_aio_post_pwrite(void *iocb, int fd, size_t count, long long offset);