1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
|
---
title: "Troubleshoot The Hubs"
author: "Lori Shepherd"
date: "Modified: Sept 2019. Compiled: `r format(Sys.Date(), '%d %b %Y')`"
output:
BiocStyle::html_document:
toc: true
vignette: >
% \VignetteIndexEntry{Troubleshooting The Hubs}
% \VignetteEngine{knitr::rmarkdown}
% \VignetteEncoding{UTF-8}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(eval = FALSE)
```
# Overview
In spring 2019 the Hubs ([AnnotationHub][]/[ExperimentHub][]) upgraded their
backend to utilize [BiocFileCache][]. This upgrade changed how resources were
downloaded and saved. While the Hub code itself ensures validity, it is possible
to access the `BiocFileCache` of resources directly without the Hub front ends,
which opens up the possibility of having caching problems. This document will
touch on some troubleshooting for these issues as well as any other frequently
asked issues. If the question or answer cannot be found here please ask on the
[Bioconductor Support Site][] or on the mailing list
`<bioc-devel@r-project.org>`
# Troubleshooting
## Invalid Cache
An invalid cache ERROR results from a missing sqlite or index file in the Hub's
BiocFileCache. The Hub code needs these files in order to operate
correctly. Rerun the Hub constructor (`AnnotationHub()` or `ExperimentHub()`)
again. If you were trying to run the constructor with `localHub=TRUE`, you
will have to run `localHub=FALSE` at least once to redownload the Hub sqlite
file.
## Corrupt Cache
A corrupt cache ERROR results from multiple entries in the BiocFileCache
matching a query for a particular file. This will involve removing one,
multiple, or all entries for a file. Please see specific section below although
all follow the same principles.
### sqlite file
If the sqlite file is the problematic file you should see something like the
following (maybe be experimenthub.sqlite3 respectively)
```
> ah = AnnotationHub()
Error: Corrupt Cache: sqlite file
See AnnotationHub's TroubleshootingTheCache vignette section on corrupt cache
cache: /home/lori/.cache/AnnotationHub
filename: annotationhub.sqlite3
```
You will need to investigate the underlying BiocFileCache for the Hub and remove
some or all of the files so that there is only a single entry for the
filename. Call the BiocFileCache constructor with the path listed as `cache` in
the ERROR message.
```
library(BiocFileCache)
bfc <- BiocFileCache("/home/lori/.cache/AnnotationHub")
```
Now we can query the BiocFileCache using the `filename` of the ERROR message.
This shows the number of entries for the filename. There should only be one row
```
res <- bfcquery(bfc, "annotationhub.sqlite3", field="rname", exact=TRUE)
res
# A tibble: 2 x 10
rid rname create_time access_time rpath rtype fpath last_modified_t… etag
<chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 BFC1 anno… 2019-03-05… 2019-03-06… /hom… web http… 2019-02-19 19:1… NA
2 BFC13 anno… 2019-03-06… 2019-03-06… /hom… rela… /hom… NA NA
# … with 1 more variable: expires <dbl>
```
You will need to deterime if you can validate which entry should remain by
evaluating the entries in the cache; [dplyr package][] methods may be useful for
parsing the tibble res object.
If you can identify which entry should be kept - remove the other entries in
the cache or rename the rname by calling the BiocFileCache functions bfcremove
or bfcupdate with the rid of the offending entries
```
library(dplyr)
res %>% select(rid, rname, rpath, fpath)
# example of rename the rname
bfcupdate(bfc, rids="BFC13", rname="What I am renaming the rname to")
# example remove
bfcremove(bfc, rids="BFC13")
```
If you cannot figure out which entry should be kept I recommend removing all
entries so that a fresh redownload can occur. Then call the Hub constructor.
```
bfcremove(bfc, rids=res$rid)
ah = AnnotationHub()
```
#### redownload of sqlite file
A force redownload of the sqlite hub file can be achieved through the refreshHub
function. To specify which of the Bioconductor Hubs to redownload use the
hubClass argument with either AnnotationHub or ExperimentHub.
```
ah2 = refreshHub(hubClass="AnnotationHub")
```
### index file
If the index file is the problematic file you should see something like the
following (maybe be experimenthub.index.rds respectively)
```
> ah = AnnotationHub()
snapshotDate(): 2019-02-19
Error: Corrupt Cache: index file
See AnnotationHub's TroubleshootingTheCache vignette section on corrupt cache
cache: /home/lori/.cache/AnnotationHub
filename: annotationhub.index.rds
```
You will need to investigate the underlying BiocFileCache for the Hub and remove
some or all of the files so that there is only a single entry for the
filename. Call the BiocFileCache constructor with the path listed as `cache` in
the ERROR message.
```
library(BiocFileCache)
bfc <- BiocFileCache("/home/lori/.cache/AnnotationHub")
```
Now we can query the BiocFileCache using the `filename` of the ERROR message.
This shows the number of entries for the filename. There should only be one row
```
res <- bfcquery(bfc, "annotationhub.index.rds", field="rname", exact=TRUE)
res
# A tibble: 2 x 10
rid rname create_time access_time rpath rtype fpath last_modified_t… etag
<chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 BFC2 anno… 2019-03-05… 2019-03-05… /hom… rela… 66d4… NA NA
2 BFC14 anno… 2019-03-06… 2019-03-06… /hom… rela… /hom… NA NA
# … with 1 more variable: expires <dbl>
```
You will need to deterime if you can validate which entry should remain by
evaluating the entries in the cache; [dplyr package][] methods may be useful for
parsing the tibble res object.
If you can identify which entry should be kept - remove the other entries in
the cache or rename the rname by calling the BiocFileCache functions bfcremove
or bfcupdate with the rid of the offending entries
```
library(dplyr)
res %>% select(rid, rname, rpath, fpath)
# example of rename the rname
bfcupdate(bfc, rids="BFC14", rname="What I am renaming the rname to")
# example remove
bfcremove(bfc, rids="BFC14")
```
If you cannot figure out which entry should be kept I recommend removing all
entries so that a fresh redownload can occur. Then call the Hub constructor.
```
bfcremove(bfc, rids=res$rid)
ah = AnnotationHub()
```
### resource path
If the resource path is a problem, this indicates that there may be duplicate
files in the cache. There may only exist at any given time one downloaded file
path per resource as indicated by the filename schema "<random
identifier>_<resource id>`. This ERROR indicates duplicate values `_<resource id>`
The ERROR should look similar to
```
Error: Corrupt Cache: resource path
See AnnotationHub's TroubleshootingTheCache vignette section on corrupt cache
cache: /home/lori/.cache/AnnotationHub
potential duplicate files:
499d6769cf1d_5012
66d42a51a258_5012
```
You will need to investigate the underlying BiocFileCache for the Hub and remove
some or all of the files so that there is only a single entry for the
resource path. Call the BiocFileCache constructor with the path listed as `cache` in
the ERROR message.
```
library(BiocFileCache)
bfc <- BiocFileCache("/home/lori/.cache/AnnotationHub")
```
Now we can query the BiocFileCache using the `duplicate files` of the ERROR message.
```
res <- bfcquery(bfc, "5012", field="rpath", exact=FALSE)
res
# A tibble: 2 x 10
rid rname create_time access_time rpath rtype fpath last_modified_t… etag
<chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 BFC3 AH50… 2019-03-05… 2019-03-05… /hom… web http… 2014-03-28 09:2… dd0c…
2 BFC19 dup … 2019-03-06… 2019-03-06… /hom… web http… 2014-03-28 09:2… dd0c…
# … with 1 more variable: expires <dbl>
```
You will need to deterime if you can validate which entry should remain by
evaluating the entries in the cache; [dplyr package][] methods may be useful for
parsing the tibble res object.
If you can identify which entry should be kept - remove the other entries in
the cache or rename the rname by calling the BiocFileCache functions
bfcremove. If you cannot the best appropate is to remove the resource and
redownload a new entry.
```
# remove single entry
bfcremove(bfc, rids="BFC19")
# remove all
bfcremove(bfc, rids=res$rid)
```
If the query resulted in only one entry, there is likely a file in your cache
location that has the format similar to the entry in the cache and will have to
be removed or renamed. An example
```
Error: Corrupt Cache: resource path
See AnnotationHub's TroubleshootingTheCache vignette section on corrupt cache
cache: /home/lori/.cache/AnnotationHub
potential duplicate files:
45b42ba7aaa1_38317
7a4726896632_38317
```
But when you do the query there is only one value
```
> res <- bfcquery(bfc, "38317", field="rpath", exact=FALSE)
> res
# A tibble: 1 x 10
rid rname create_time access_time rpath rtype fpath last_modified_t… etag
<chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 BFC37 AH32… 2019-03-08… 2019-03-08… /hom… web http… 2013-07-25 07:0… 11c3…
# … with 1 more variable: expires <dbl>
```
The file path of the valid entry is
```
> bfcinfo(bfc, rid="BFC37") %>% dplyr::select(rpath)
# A tibble: 1 x 1
rpath
<chr>
1 /home/lori/.cache/AnnotationHub/45b42ba7aaa1_38317
```
Therefore we would want to move or rename the file `7a4726896632_38317`.
```
> fl <- file.path(bfccache(bfc), "7a4726896632_38317")
> fl
[1] "/home/lori/.cache/AnnotationHub/7a4726896632_38317"
> unlink(fl)
```
### resource id
If the resource id is problematic, it generally means that there are entries in
the BiocFileCache with the same `rname`. You would see an ERROR similar to the
following:
```
> cache(ah[1:4])
adding rname 'AH5015 : 5015'
Error: Corrupt Cache: resource id
See AnnotationHub's TroubleshootingTheCache vignette section on corrupt cache
cache: /home/lori/.cache/AnnotationHub
reason: not all 'rnames' found or unique.
```
You will need to investigate the underlying BiocFileCache for the Hub and remove
or rename resources so there are no duplicate rnames in the cache.
```
library(BiocFileCache)
bfc <- BiocFileCache("/home/lori/.cache/AnnotationHub")
bfcinfo(bfc) %>% dplyr::select(rname)
```
You can remove with `bfcremove` and can rename with `bfcupdate`.
## Corrupt Database
A corrupt hub database ERROR results from an invalid hub sqlite file. Perhaps
the original download was interrupted or the file was overwritten.
You will have to remove the currently downloaded sqlite file so it can be
redownloaded.
The output you received looked something similar to the following:
```
> ah = AnnotationHub()
Error: Corrupt Hub Database; See AnnotationHub's TroubleshootingTheCache vignette section on corrupt database
database: '/home/lori/.cache/AnnotationHub/66d467fcefa5_annotationhub.sqlite3'
reason: missing tables
```
The simplest solution is to remove the file listed as the `database:` in the
above output.
```
# from the example above
file.remove('/home/lori/.cache/AnnotationHub/66d467fcefa5_annotationhub.sqlite3')
```
Rerunning the constructor should now redownload a valid database object.
## Cannot retrieve resource
This occurs when using a Hub object designated to only access locally downloaded
files (ex. hub <- `AnnotationHub(localHub=TRUE)`) and a resource cannot be found in
the current BiocFileCache database. The ERROR looks similar to
```
Error: Cannot retrieve resource
Rerun constructor with 'localHub=FALSE' or exclude ID
Requested resource not found in local cache:
AH66165 : 72911
```
The options are to change the Hub object to `isLocalHub=FALSE`
(`isLocalHub(hub)<-FALSE`) so the file can be downloaded. If this cannot be done
because of internet access or other issues, the resource will not be
available. If this was part of a subset to download, remove the resource id from
the subset.
## Offline localHub usage
There is a flag in the constructor `localHub=TRUE` to use only show previously
downloaded resources. If you are using this in an offline setting, please also
see the [BiocManager vignette on offline
use](https://cran.r-project.org/web/packages/BiocManager/vignettes/BiocManager.html#offline-use). The
Hubs use BiocManager::version to filter resources appropriate for your current
version of R/Bioconductor; therefore the offline usage of BiocManager needs to
be established.
The error that occurs that likely needs offline set up will look similar to the
following:
```
ExperimentHub(localHub=TRUE)
Error: failed to connect to local data base
database: ‘/home/user/.cache/R/ExperimentHub/24dc84dbf615e_experimenthub.sqlite3’
reason: invalid version specification ‘Bioconductor version cannot be validated; no internet connection?’`
```
# Group Hub/Cache Access
The situation may occur where a hub is desired to be shared across multiple
users on a system. This presents permissions errors. To allow access to
multiple users create a group that the users belong to and that the underlying
hub cache belongs too. Permissions of potentially two files need to be altered depending
on what you would like individuals to be able to accomplish with the hub. A
read-only hub will require manual manipulatios of the file
BiocFileCache.sqlite.LOCK so that the group permissions are `g+rw`. To allow
users to download files to the shared hub, both the
BiocFileCache.sqlite.LOCK file and the BiocFileCache.sqlite file will need group
permissions to `g+rw`. Please google how to create a user group for your system
of interest. To find the location of the hub cache to be able to change the group
and file permissions, you may run the following in R `ah = AnnotationHub();
hubCache(ah)`. For quick reference in linux you will use `chown
currentuser:newgroup` to change the group and `chmod` to change the file
permissions: `chmod 660` or `chmod g+rw` should accomplish the correct
permissions.
# Lock file Troubleshooting
Two issues have been commonly reported regarding the lock file.
## Permissions
There could be permission ERROR regarding group and public access. See the
previous `Group Cache Access` section.
## Cannot lock file / no lock available
This is an issue with filelock on particular systems. Particular partitions and
non standard file systems may not support filelock. The solution is to use a
different section of the system to create the cache. The easiest way to define a
new cache location is by using environment variables.
In R:
`Sys.setenv(BFC_CACHE=<new cache location>)`
Alternatively, you can set an environment variable globally to avoid having to
set uniquely in each R session. Please google for specific instructions for
setting environment variables globally for your particular OS system.
Other common filelock implemented packages that have specific environment
variables to control location are:
* BiocFileCache: BFC_CACHE
* ExperimentHub: EXPERIMENT_HUB_CACHE
* AnnotationHub: ANNOTATION_HUB_CACHE
* biomaRt: BIOMART_CACHE
# Default Caching Location Update
As of AnnotationHub version > 2.23.2, the default caching location has
changed. The default cache is now controlled by the function `tools::R_user_dir`
instead of `rappdirs::user_cache_dir`. Users who have utilized the default
AnnotationHub location, to continue using the created cache, must move the cache and its
files to the new default location, create a system environment variable to
point to the old location, or delete and start a new cache.
## Option 1: Move cache and files to new location
The following steps can be used to move the files to the new location:
1. Determine the old location by running the following in R
`rappdirs::user_cache_dir(appname="AnnotationHub")`
2. Determine the new location by running the following in R
`tools::R_user_dir("AnnotationHub", which="cache")`
3. Move the files to the new location. You can do this manually or do the
following steps in R. Remember if you have a lot of cached files, this may take
awhile.
```{r, eval=FALSE}
# make sure you have permissions on the cache/files
# use at own risk
moveFiles<-function(package){
olddir <- path.expand(rappdirs::user_cache_dir(appname=package))
newdir <- tools::R_user_dir(package, which="cache")
dir.create(path=newdir, recursive=TRUE)
files <- list.files(olddir, full.names =TRUE)
moveres <- vapply(files,
FUN=function(fl){
filename = basename(fl)
newname = file.path(newdir, filename)
file.rename(fl, newname)
},
FUN.VALUE = logical(1))
if(all(moveres)) unlink(olddir, recursive=TRUE)
}
package="AnnotationHub"
moveFiles(package)
```
## Option 2: Create a system environment variable
A user may set the system environment variable `ANNOTATION_HUB_CACHE` to control
the default location of the cache. Setting system environment variables can vary
depending on the operating system; we suggest using google to find appropriate
instructures per your operating system.
You will want to set the variable to the results of running the following in R:
```{r, eval=FALSE}
path.expand(rappdirs::user_cache_dir(appname="AnnotationHub"))
```
**NOTE:** R has `Sys.setenv` however that will only set the variable for that R
session. It would not be available or recognized in future R sessions. It is
important to set the variable as a global user-wide or system-wide
environment variable so it persists in all future logins to your system.
## Option 3: Delete the old cache
Lastly, if a user does not care about the already existing default cache, the
old location may be deleted to move forward with the new default location. This
option should be used with caution. Once deleted, old cached resources will no
longer be available and have to be re-downloaded.
One can do this manually by navigating to the location indicated in the ERROR
message as `Problematic cache:` and deleting the folder and all its content.
The following can be done to delete through R code:
**CAUTION** This will remove the old cache and all downloaded resources. All
resources will have to be re-downloaded after executing this code.
```{r, eval=FALSE}
library(AnnotationHub)
package = "AnnotationHub"
oldcache = path.expand(rappdirs::user_cache_dir(appname=package))
setAnnotationHubOption("CACHE", oldcache)
ah = AnnotationHub(localHub=TRUE)
## removes old location and all resources
removeCache(ah, ask=FALSE)
## create the new default caching location
newcache = tools::R_user_dir(package, which="cache")
setAnnotationHubOption("CACHE", newcache)
ah = AnnotationHub()
```
[Bioconductor Support Site]: https://support.bioconductor.org/
[AnnotationHub]: https://bioconductor.org/packages/AnnotationHub/
[ExperimentHub]: https://bioconductor.org/packages/ExperimentHub/
[BiocFileCache]: https://bioconductor.org/packages/BiocFileCache/
[dplyr]: https://www.rdocumentation.org/packages/dplyr/versions/0.7.8
|