ftruncate(fd, 5 << 20); // FIXME
close(fd);
}
-
- // If the log file is stored in the cloud, we may need to fetch it
- if (clouddir >= 0 && start_fetch)
- cloudlog_fetch_start(map);
} else {
g_mutex_lock(map->lock);
}
+
+ /* If the log file is stored in the cloud and has not been fully fetched,
+ * we may need to initiate a fetch now. */
+ if (clouddir >= 0 && start_fetch && !map->complete && !map->fetching)
+ cloudlog_fetch_start(map);
+
g_mutex_unlock(log->mmap_lock);
if (map != NULL)
g_atomic_int_inc(&map->refcount);
size_t offset, size_t length)
{
g_atomic_int_inc(&cachefile->refcount);
- g_print("Starting fetch of %s from cloud\n", cachefile->filename);
+ g_print("Starting partial fetch of %s from cloud (%zd + %zd)\n",
+ cachefile->filename, offset, length);
BlueSkyStoreAsync *async = bluesky_store_async_new(cachefile->fs->store);
async->op = STORE_OP_GET;
async->key = g_strdup(cachefile->filename);
file_offset);
}
if (range_request) {
- uint64_t start = 0, length = 0, end;
+ uint64_t start = file_offset, length = file_size, end;
if (map->prefetches != NULL)
bluesky_rangeset_get_extents(map->prefetches,
&start, &length);
} else if (rangeitem->start == file_offset
&& rangeitem->length == file_size) {
if (bluesky_verbose)
- g_print("Item now available.\n");
+ g_print("Item %zd now available.\n", file_offset);
break;
}
}
if (g_atomic_int_dec_and_test(&mmap->mapcount)) {
g_mutex_lock(mmap->lock);
- if (g_atomic_int_get(&mmap->mapcount) == 0) {
+ if (mmap->addr != NULL) {
if (bluesky_verbose)
g_print("Unmapped log segment %d...\n", mmap->log_seq);
munmap((void *)mmap->addr, mmap->len);
}
g_mutex_unlock(mmap->lock);
}
+ g_assert(g_atomic_int_get(&mmap->mapcount) >= 0);
}
/******************************* JOURNAL REPLAY *******************************