src/backend/replication/logical/reorderbuffer.c
void
StartupReorderBuffer(void)
{
	DIR		   *logical_dir;
	struct dirent *logical_de;

	DIR		   *spill_dir;
	struct dirent *spill_de;

	logical_dir = AllocateDir("pg_replslot");
	while ((logical_de = ReadDir(logical_dir, "pg_replslot")) != NULL)
	{
		struct stat statbuf;
		char		path[MAXPGPATH];

		if (strcmp(logical_de->d_name, ".") == 0 ||
			strcmp(logical_de->d_name, "..") == 0)
			continue;

		/* if it cannot be a slot, skip the directory */
		if (!ReplicationSlotValidateName(logical_de->d_name, DEBUG2))
			continue;

		/*
		 * ok, has to be a surviving logical slot, iterate and delete
		 * everythign starting with xid-*
		 */
		sprintf(path, "pg_replslot/%s", logical_de->d_name);

		/* we're only creating directories here, skip if it's not our's */
		if (lstat(path, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
			continue;

		spill_dir = AllocateDir(path);
		while ((spill_de = ReadDir(spill_dir, path)) != NULL)
		{
			if (strcmp(spill_de->d_name, ".") == 0 ||
				strcmp(spill_de->d_name, "..") == 0)
				continue;

			/* only look at names that can be ours */
			if (strncmp(spill_de->d_name, "xid", 3) == 0)
			{
				sprintf(path, "pg_replslot/%s/%s", logical_de->d_name,
						spill_de->d_name);

				if (unlink(path) != 0)
					ereport(PANIC,
							(errcode_for_file_access(),
							 errmsg("could not remove file \"%s\": %m",
									path)));
			}
		}
		FreeDir(spill_dir);
	}
	FreeDir(logical_dir);
}
/*
 * Delete all data spilled to disk after we've restarted/crashed. It will be
 * recreated when the respective slots are reused.
 */
Delete all data spilled to disk after we've restarted/crashed. It will be
recreated when the respective slots are reused.
Delete all data spilled to disk after we ' ve restarted / crashed . It will be recreated when the respective slots are reused .
void
StartupReorderBuffer(void)
{
	DIR		   *logical_dir;
	struct dirent *logical_de;
	DIR		   *spill_dir;
	struct dirent *spill_de;
	logical_dir = AllocateDir("pg_replslot");
	while ((logical_de = ReadDir(logical_dir, "pg_replslot")) != NULL)
	{
		struct stat statbuf;
		char		path[MAXPGPATH];
		if (strcmp(logical_de->d_name, ".") == 0 ||
			strcmp(logical_de->d_name, "..") == 0)
			continue;
		if (!ReplicationSlotValidateName(logical_de->d_name, DEBUG2))
			continue;
		sprintf(path, "pg_replslot/%s", logical_de->d_name);
		if (lstat(path, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
			continue;
		spill_dir = AllocateDir(path);
		while ((spill_de = ReadDir(spill_dir, path)) != NULL)
		{
			if (strcmp(spill_de->d_name, ".") == 0 ||
				strcmp(spill_de->d_name, "..") == 0)
				continue;
			if (strncmp(spill_de->d_name, "xid", 3) == 0)
			{
				sprintf(path, "pg_replslot/%s/%s", logical_de->d_name,
						spill_de->d_name);
				if (unlink(path) != 0)
					ereport(PANIC,
							(errcode_for_file_access(),
							 errmsg("could not remove file \"%s\": %m",
									path)));
			}
		}
		FreeDir(spill_dir);
	}
	FreeDir(logical_dir);
}
void StartupReorderBuffer ( void ) { DIR * logical_dir ; struct dirent * logical_de ; DIR * spill_dir ; struct dirent * spill_de ; logical_dir = AllocateDir ( " " ) ; while ( ( logical_de = ReadDir ( logical_dir , " " ) ) != NULL ) { struct stat statbuf ; char path [ MAXPGPATH ] ; if ( strcmp ( logical_de -> d_name , " " ) == 0 || strcmp ( logical_de -> d_name , " " ) == 0 ) continue ; if ( ! ReplicationSlotValidateName ( logical_de -> d_name , DEBUG2 ) ) continue ; sprintf ( path , " " , logical_de -> d_name ) ; if ( lstat ( path , & statbuf ) == 0 && ! S_ISDIR ( statbuf . st_mode ) ) continue ; spill_dir = AllocateDir ( path ) ; while ( ( spill_de = ReadDir ( spill_dir , path ) ) != NULL ) { if ( strcmp ( spill_de -> d_name , " " ) == 0 || strcmp ( spill_de -> d_name , " " ) == 0 ) continue ; if ( strncmp ( spill_de -> d_name , " " , 3 ) == 0 ) { sprintf ( path , " " , logical_de -> d_name , spill_de -> d_name ) ; if ( unlink ( path ) != 0 ) ereport ( PANIC , ( errcode_for_file_access ( ) , errmsg ( " \" \" " , path ) ) ) ; } } FreeDir ( spill_dir ) ; } FreeDir ( logical_dir ) ; }
Delete all data spilled to disk after we've restarted/crashed.
Delete all data spilled to disk after we ' ve restarted / crashed .
/* if it cannot be a slot, skip the directory */ /*
		 * ok, has to be a surviving logical slot, iterate and delete
		 * everythign starting with xid-*
		 */ /* we're only creating directories here, skip if it's not our's */ /* only look at names that can be ours */