~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/falcon/SerialLogFile.cpp

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
179
179
                priority.schedule(PRIORITY_HIGH);
180
180
                
181
181
#ifdef _WIN32
182
 
        
183
 
        Sync sync(&syncObject, "SerialLogFile::write");
184
 
        sync.lock(Exclusive);
185
 
        
186
 
        if (position != offset)
187
 
                {
188
 
                LARGE_INTEGER pos;
189
 
                pos.QuadPart = position;
190
 
 
191
 
                if (!SetFilePointerEx(handle, pos, NULL, FILE_BEGIN))
192
 
                        throw SQLError(IO_ERROR, "serial log SetFilePointerEx failed with %d", GetLastError());
193
 
                }
 
182
        LARGE_INTEGER pos;
 
183
        pos.QuadPart = position;
 
184
        OVERLAPPED overlapped = {0};
 
185
        overlapped.Offset = pos.LowPart;
 
186
        overlapped.OffsetHigh = pos.HighPart;
194
187
 
195
188
        DWORD ret;
196
189
        
197
 
        if (!WriteFile(handle, data, effectiveLength, &ret, NULL))
 
190
        if (!WriteFile(handle, data, effectiveLength, &ret, &overlapped))
198
191
                {
199
192
                int lastError = GetLastError();
200
193
                
219
212
                if (loc != position)
220
213
                        throw SQLEXCEPTION (IO_ERROR, "serial lseek error on \"%s\": %s (%d)", 
221
214
                                                                (const char*) fileName, strerror (errno), errno);
222
 
 
223
215
                }
224
216
 
225
217
        uint32 n = ::write(handle, data, effectiveLength);
226
218
        
 
219
#endif
 
220
 
227
221
        if (forceFsync)
228
222
                fsync(handle);
229
 
#endif
230
223
 
231
224
        if (n != effectiveLength)
232
225
                {
259
252
                priority.schedule(PRIORITY_HIGH);
260
253
 
261
254
#ifdef _WIN32
262
 
        Sync sync(&syncObject, "SerialLogFile::read");
263
 
        sync.lock(Exclusive);
 
255
 
264
256
        ASSERT(position < writePoint || writePoint == 0);
265
257
        LARGE_INTEGER pos;
266
258
        pos.QuadPart = position;
267
 
        
268
 
        if (!SetFilePointerEx(handle, pos, NULL, FILE_BEGIN))
269
 
                throw SQLError(IO_ERROR, "serial log SetFilePointer failed with %d", GetLastError());
 
259
        OVERLAPPED overlapped = {0};
 
260
        overlapped.Offset = pos.LowPart;
 
261
        overlapped.OffsetHigh = pos.HighPart;
270
262
 
271
263
        DWORD ret;
272
264
 
273
 
        if (!ReadFile(handle, data, effectiveLength, &ret, NULL))
 
265
        if (!ReadFile(handle, data, effectiveLength, &ret, &overlapped))
274
266
                throw SQLError(IO_ERROR, "serial log ReadFile failed with %d", GetLastError());
275
267
 
276
268
        offset = position + effectiveLength;
305
297
#endif
306
298
}
307
299
 
 
300
void SerialLogFile::truncate(int64 size)
 
301
{
 
302
#ifdef _WIN32
 
303
        LARGE_INTEGER oldPos, distance;
 
304
        distance.QuadPart = 0;
 
305
 
 
306
        // Get current position in file 
 
307
        if (!SetFilePointerEx(handle, distance ,&oldPos,FILE_CURRENT))
 
308
                throw SQLError(IO_ERROR, "SetFilePointerEx failed with %d", 
 
309
                                                GetLastError());
 
310
 
 
311
        // Position to the new end of file , set EOF marker there
 
312
        distance.QuadPart = size;
 
313
        if (!SetFilePointerEx(handle, distance, 0, FILE_BEGIN))
 
314
                throw SQLError(IO_ERROR, "SetFilePointerEx failed with %d", 
 
315
                                                GetLastError());
 
316
 
 
317
        if (!SetEndOfFile(handle))
 
318
                throw SQLError(IO_ERROR, "SetEndOfFile failed with %d", 
 
319
                                                GetLastError());
 
320
 
 
321
 
 
322
        // Restore file pointer
 
323
        if (!SetFilePointerEx(handle, oldPos ,0,FILE_BEGIN))
 
324
                throw SQLError(IO_ERROR, "SetFilePointerEx failed with %d", 
 
325
                                                GetLastError());
 
326
#else
 
327
        if (ftruncate(handle, size))
 
328
                throw SQLError(IO_ERROR, "ftruncate failed with %d", 
 
329
                                                errno);
 
330
#endif
 
331
}
 
332
 
 
333
int64 SerialLogFile::size(void)
 
334
{
 
335
#ifdef _WIN32
 
336
        LARGE_INTEGER size;
 
337
 
 
338
        if (!GetFileSizeEx(handle, &size))
 
339
                throw SQLError(IO_ERROR, "GetFileSizeEx failed with %u", 
 
340
                                                GetLastError());
 
341
 
 
342
        return size.QuadPart;
 
343
#else
 
344
        struct stat buf;
 
345
        if (fstat(handle, &buf))
 
346
                throw SQLError(IO_ERROR, "stat failed with %d",
 
347
                                                errno);
 
348
        return  buf.st_size;
 
349
#endif
 
350
}
308
351
 
309
352
void SerialLogFile::zap()
310
353
{