validateWrites will check whether the given requests can fit into 4GB vlog file. NOTE: 4GB is the maximum size we can create for vlog because value pointer offset is of type uint32. If we create more than 4GB, it will overflow uint32. So, limiting the size to 4GB.
(reqs []*request)
| 1372 | // NOTE: 4GB is the maximum size we can create for vlog because value pointer offset is of type |
| 1373 | // uint32. If we create more than 4GB, it will overflow uint32. So, limiting the size to 4GB. |
| 1374 | func (vlog *valueLog) validateWrites(reqs []*request) error { |
| 1375 | vlogOffset := uint64(vlog.woffset()) |
| 1376 | for _, req := range reqs { |
| 1377 | // calculate size of the request. |
| 1378 | size := estimateRequestSize(req) |
| 1379 | estimatedVlogOffset := vlogOffset + size |
| 1380 | if estimatedVlogOffset > uint64(maxVlogFileSize) { |
| 1381 | return errors.Errorf("Request size offset %d is bigger than maximum offset %d", |
| 1382 | estimatedVlogOffset, maxVlogFileSize) |
| 1383 | } |
| 1384 | |
| 1385 | if estimatedVlogOffset >= uint64(vlog.opt.ValueLogFileSize) { |
| 1386 | // We'll create a new vlog file if the estimated offset is greater or equal to |
| 1387 | // max vlog size. So, resetting the vlogOffset. |
| 1388 | vlogOffset = 0 |
| 1389 | continue |
| 1390 | } |
| 1391 | // Estimated vlog offset will become current vlog offset if the vlog is not rotated. |
| 1392 | vlogOffset = estimatedVlogOffset |
| 1393 | } |
| 1394 | return nil |
| 1395 | } |
| 1396 | |
| 1397 | // estimateRequestSize returns the size that needed to be written for the given request. |
| 1398 | func estimateRequestSize(req *request) uint64 { |