7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
9
* IDENTIFICATION
10
- * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.122 2005/11/22 18:17:20 momjian Exp $
10
+ * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.123 2005/12/01 20:24:18 tgl Exp $
11
11
*
12
12
* NOTES:
13
13
*
@@ -1009,11 +1009,41 @@ FileRead(File file, char *buffer, int amount)
1009
1009
if (returnCode < 0 )
1010
1010
return returnCode ;
1011
1011
1012
+ retry :
1012
1013
returnCode = read (VfdCache [file ].fd , buffer , amount );
1013
- if (returnCode > 0 )
1014
+
1015
+ if (returnCode >= 0 )
1014
1016
VfdCache [file ].seekPos += returnCode ;
1015
1017
else
1018
+ {
1019
+ /*
1020
+ * Windows may run out of kernel buffers and return "Insufficient
1021
+ * system resources" error. Wait a bit and retry to solve it.
1022
+ *
1023
+ * It is rumored that EINTR is also possible on some Unix filesystems,
1024
+ * in which case immediate retry is indicated.
1025
+ */
1026
+ #ifdef WIN32
1027
+ DWORD error = GetLastError ();
1028
+
1029
+ switch (error )
1030
+ {
1031
+ case ERROR_NO_SYSTEM_RESOURCES :
1032
+ pg_usleep (1000L );
1033
+ errno = EINTR ;
1034
+ break ;
1035
+ default :
1036
+ _dosmaperr (error );
1037
+ break ;
1038
+ }
1039
+ #endif
1040
+ /* OK to retry if interrupted */
1041
+ if (errno == EINTR )
1042
+ goto retry ;
1043
+
1044
+ /* Trouble, so assume we don't know the file position anymore */
1016
1045
VfdCache [file ].seekPos = FileUnknownPos ;
1046
+ }
1017
1047
1018
1048
return returnCode ;
1019
1049
}
@@ -1033,17 +1063,42 @@ FileWrite(File file, char *buffer, int amount)
1033
1063
if (returnCode < 0 )
1034
1064
return returnCode ;
1035
1065
1066
+ retry :
1036
1067
errno = 0 ;
1037
1068
returnCode = write (VfdCache [file ].fd , buffer , amount );
1038
1069
1039
1070
/* if write didn't set errno, assume problem is no disk space */
1040
1071
if (returnCode != amount && errno == 0 )
1041
1072
errno = ENOSPC ;
1042
1073
1043
- if (returnCode > 0 )
1074
+ if (returnCode >= 0 )
1044
1075
VfdCache [file ].seekPos += returnCode ;
1045
1076
else
1077
+ {
1078
+ /*
1079
+ * See comments in FileRead()
1080
+ */
1081
+ #ifdef WIN32
1082
+ DWORD error = GetLastError ();
1083
+
1084
+ switch (error )
1085
+ {
1086
+ case ERROR_NO_SYSTEM_RESOURCES :
1087
+ pg_usleep (1000L );
1088
+ errno = EINTR ;
1089
+ break ;
1090
+ default :
1091
+ _dosmaperr (error );
1092
+ break ;
1093
+ }
1094
+ #endif
1095
+ /* OK to retry if interrupted */
1096
+ if (errno == EINTR )
1097
+ goto retry ;
1098
+
1099
+ /* Trouble, so assume we don't know the file position anymore */
1046
1100
VfdCache [file ].seekPos = FileUnknownPos ;
1101
+ }
1047
1102
1048
1103
return returnCode ;
1049
1104
}
0 commit comments