{"action":"created","comment":{"url":"https://api.github.com/repos/ipfs/go-ipfs/pulls/comments/34968943","id":34968943,"diff_hunk":"@@ -246,6 +250,41 @@ func daemonFunc(req cmds.Request, res cmds.Response) {\n \t\t}\n \t}\n \n+\t// repo blockstore GC\n+\tconst storageMax = 1024 * 1024 * 1024 // 1 GB\n+\tconst storageGcWatermark = storageMax / 10 * 9\n+\n+\tgo func() {\n+\t\tfor {\n+\t\t\t<-time.After(30 * time.Minute)\n+\n+\t\t\t// Check fs repo disk usage\n+\t\t\tdiskUsage, err := fsrepo.GetDiskUsage()\n+\t\t\tif err != nil {\n+\t\t\t\tres.SetError(err, cmds.ErrNormal)\n+\t\t\t}\n+\n+\t\t\tif diskUsage > storageMax {\n+\t\t\t\tres.SetError(errors.New(\"Maximum storage limit exceeded. Maybe unpin some files?\"), cmds.ErrNormal)\n+\t\t\t} else if diskUsage > storageGcWatermark {\n+\t\t\t\tfmt.Println(\"Starting repo GC...\")\n+\t\t\t\t// 1 minute is sufficient for ~1GB unlink() blocks each of 100kb in SSD\n+\t\t\t\t// TODO: scale this, e.g. multiply by (diskUsage / 10e9)\n+\t\t\t\tctx, cancel := context.WithTimeout(context.TODO(), time.Minute)\n+\t\t\t\tdefer cancel()\n+\t\t\t\tif err := corerepo.GarbageCollect(node, ctx); err != nil {\n+\t\t\t\t\tres.SetError(err, cmds.ErrNormal)\n+\t\t\t\t}\n+\t\t\t\tnewDiskUsage, err := fsrepo.GetDiskUsage()\n+\t\t\t\tif err != nil {\n+\t\t\t\t\tres.SetError(err, cmds.ErrNormal)\n+\t\t\t\t}\n+\t\t\t\t// TODO: Add unit to \"Released x KB/MB/GB/TB/PB\"\n+\t\t\t\tfmt.Println(\"Repo GC done. Released %d\", newDiskUsage-diskUsage)\n+\t\t\t}\n+\t\t}\n+\t}()","path":"cmd/ipfs/daemon.go","position":64,"original_position":64,"commit_id":"7ed7f35969a16b100f26d4134d6243ad26ecf23b","original_commit_id":"7ed7f35969a16b100f26d4134d6243ad26ecf23b","user":{"login":"jbenet","id":138401,"avatar_url":"https://avatars.githubusercontent.com/u/138401?v=3","gravatar_id":"","url":"https://api.github.com/users/jbenet","html_url":"https://github.com/jbenet","followers_url":"https://api.github.com/users/jbenet/followers","following_url":"https://api.github.com/users/jbenet/following{/other_user}","gists_url":"https://api.github.com/users/jbenet/gists{/gist_id}","starred_url":"https://api.github.com/users/jbenet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbenet/subscriptions","organizations_url":"https://api.github.com/users/jbenet/orgs","repos_url":"https://api.github.com/users/jbenet/repos","events_url":"https://api.github.com/users/jbenet/events{/privacy}","received_events_url":"https://api.github.com/users/jbenet/received_events","type":"User","site_admin":false},"body":"this file/function is already a huge mess. we'll want to split this out. \r\n\r\nthis stuff belongs in the `fs-repo` package. I think maybe we can pass an option all the way in as to whether to initialize with GC or not. (or even no option, assume always so.","created_at":"2015-07-20T05:21:54Z","updated_at":"2015-07-20T05:21:54Z","html_url":"https://github.com/ipfs/go-ipfs/pull/1495#discussion_r34968943","pull_request_url":"https://api.github.com/repos/ipfs/go-ipfs/pulls/1495","_links":{"self":{"href":"https://api.github.com/repos/ipfs/go-ipfs/pulls/comments/34968943"},"html":{"href":"https://github.com/ipfs/go-ipfs/pull/1495#discussion_r34968943"},"pull_request":{"href":"https://api.github.com/repos/ipfs/go-ipfs/pulls/1495"}}},"pull_request":{"url":"https://api.github.com/repos/ipfs/go-ipfs/pulls/1495","id":40290357,"html_url":"https://github.com/ipfs/go-ipfs/pull/1495","diff_url":"https://github.com/ipfs/go-ipfs/pull/1495.diff","patch_url":"https://github.com/ipfs/go-ipfs/pull/1495.patch","issue_url":"https://api.github.com/repos/ipfs/go-ipfs/issues/1495","number":1495,"state":"open","locked":false,"title":"Add fixed-period repo GC","user":{"login":"rht","id":395821,"avatar_url":"https://avatars.githubusercontent.com/u/395821?v=3","gravatar_id":"","url":"https://api.github.com/users/rht","html_url":"https://github.com/rht","followers_url":"https://api.github.com/users/rht/followers","following_url":"https://api.github.com/users/rht/following{/other_user}","gists_url":"https://api.github.com/users/rht/gists{/gist_id}","starred_url":"https://api.github.com/users/rht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rht/subscriptions","organizations_url":"https://api.github.com/users/rht/orgs","repos_url":"https://api.github.com/users/rht/repos","events_url":"https://api.github.com/users/rht/events{/privacy}","received_events_url":"https://api.github.com/users/rht/received_events","type":"User","site_admin":false},"body":"WIP sketch.\r\n\r\n1. Ok with configurable GC frequency?\r\n2. go-datastore doesn't have size check, so a local system call is used instead\r\n\r\nAddress #972","created_at":"2015-07-18T10:32:32Z","updated_at":"2015-07-20T05:21:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82e00ad65c08c23f6d669972f40fd05c2eb6dfaa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ipfs/go-ipfs/pulls/1495/commits","review_comments_url":"https://api.github.com/repos/ipfs/go-ipfs/pulls/1495/comments","review_comment_url":"https://api.github.com/repos/ipfs/go-ipfs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ipfs/go-ipfs/issues/1495/comments","statuses_url":"https://api.github.com/repos/ipfs/go-ipfs/statuses/7ed7f35969a16b100f26d4134d6243ad26ecf23b","head":{"label":"rht:gc","ref":"gc","sha":"7ed7f35969a16b100f26d4134d6243ad26ecf23b","user":{"login":"rht","id":395821,"avatar_url":"https://avatars.githubusercontent.com/u/395821?v=3","gravatar_id":"","url":"https://api.github.com/users/rht","html_url":"https://github.com/rht","followers_url":"https://api.github.com/users/rht/followers","following_url":"https://api.github.com/users/rht/following{/other_user}","gists_url":"https://api.github.com/users/rht/gists{/gist_id}","starred_url":"https://api.github.com/users/rht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rht/subscriptions","organizations_url":"https://api.github.com/users/rht/orgs","repos_url":"https://api.github.com/users/rht/repos","events_url":"https://api.github.com/users/rht/events{/privacy}","received_events_url":"https://api.github.com/users/rht/received_events","type":"User","site_admin":false},"repo":{"id":35830700,"name":"go-ipfs","full_name":"rht/go-ipfs","owner":{"login":"rht","id":395821,"avatar_url":"https://avatars.githubusercontent.com/u/395821?v=3","gravatar_id":"","url":"https://api.github.com/users/rht","html_url":"https://github.com/rht","followers_url":"https://api.github.com/users/rht/followers","following_url":"https://api.github.com/users/rht/following{/other_user}","gists_url":"https://api.github.com/users/rht/gists{/gist_id}","starred_url":"https://api.github.com/users/rht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rht/subscriptions","organizations_url":"https://api.github.com/users/rht/orgs","repos_url":"https://api.github.com/users/rht/repos","events_url":"https://api.github.com/users/rht/events{/privacy}","received_events_url":"https://api.github.com/users/rht/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rht/go-ipfs","description":"ipfs implementation in go","fork":true,"url":"https://api.github.com/repos/rht/go-ipfs","forks_url":"https://api.github.com/repos/rht/go-ipfs/forks","keys_url":"https://api.github.com/repos/rht/go-ipfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rht/go-ipfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rht/go-ipfs/teams","hooks_url":"https://api.github.com/repos/rht/go-ipfs/hooks","issue_events_url":"https://api.github.com/repos/rht/go-ipfs/issues/events{/number}","events_url":"https://api.github.com/repos/rht/go-ipfs/events","assignees_url":"https://api.github.com/repos/rht/go-ipfs/assignees{/user}","branches_url":"https://api.github.com/repos/rht/go-ipfs/branches{/branch}","tags_url":"https://api.github.com/repos/rht/go-ipfs/tags","blobs_url":"https://api.github.com/repos/rht/go-ipfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rht/go-ipfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rht/go-ipfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/rht/go-ipfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rht/go-ipfs/statuses/{sha}","languages_url":"https://api.github.com/repos/rht/go-ipfs/languages","stargazers_url":"https://api.github.com/repos/rht/go-ipfs/stargazers","contributors_url":"https://api.github.com/repos/rht/go-ipfs/contributors","subscribers_url":"https://api.github.com/repos/rht/go-ipfs/subscribers","subscription_url":"https://api.github.com/repos/rht/go-ipfs/subscription","commits_url":"https://api.github.com/repos/rht/go-ipfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/rht/go-ipfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/rht/go-ipfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/rht/go-ipfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/rht/go-ipfs/contents/{+path}","compare_url":"https://api.github.com/repos/rht/go-ipfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rht/go-ipfs/merges","archive_url":"https://api.github.com/repos/rht/go-ipfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rht/go-ipfs/downloads","issues_url":"https://api.github.com/repos/rht/go-ipfs/issues{/number}","pulls_url":"https://api.github.com/repos/rht/go-ipfs/pulls{/number}","milestones_url":"https://api.github.com/repos/rht/go-ipfs/milestones{/number}","notifications_url":"https://api.github.com/repos/rht/go-ipfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rht/go-ipfs/labels{/name}","releases_url":"https://api.github.com/repos/rht/go-ipfs/releases{/id}","created_at":"2015-05-18T17:00:33Z","updated_at":"2015-05-18T17:00:35Z","pushed_at":"2015-07-19T14:30:06Z","git_url":"git://github.com/rht/go-ipfs.git","ssh_url":"git@github.com:rht/go-ipfs.git","clone_url":"https://github.com/rht/go-ipfs.git","svn_url":"https://github.com/rht/go-ipfs","homepage":"https://github.com/ipfs/ipfs","size":19623,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ipfs:master","ref":"master","sha":"8668f40915829d78916b94ed9bcfb1ff53fb0cb9","user":{"login":"ipfs","id":10536621,"avatar_url":"https://avatars.githubusercontent.com/u/10536621?v=3","gravatar_id":"","url":"https://api.github.com/users/ipfs","html_url":"https://github.com/ipfs","followers_url":"https://api.github.com/users/ipfs/followers","following_url":"https://api.github.com/users/ipfs/following{/other_user}","gists_url":"https://api.github.com/users/ipfs/gists{/gist_id}","starred_url":"https://api.github.com/users/ipfs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ipfs/subscriptions","organizations_url":"https://api.github.com/users/ipfs/orgs","repos_url":"https://api.github.com/users/ipfs/repos","events_url":"https://api.github.com/users/ipfs/events{/privacy}","received_events_url":"https://api.github.com/users/ipfs/received_events","type":"Organization","site_admin":false},"repo":{"id":21233191,"name":"go-ipfs","full_name":"ipfs/go-ipfs","owner":{"login":"ipfs","id":10536621,"avatar_url":"https://avatars.githubusercontent.com/u/10536621?v=3","gravatar_id":"","url":"https://api.github.com/users/ipfs","html_url":"https://github.com/ipfs","followers_url":"https://api.github.com/users/ipfs/followers","following_url":"https://api.github.com/users/ipfs/following{/other_user}","gists_url":"https://api.github.com/users/ipfs/gists{/gist_id}","starred_url":"https://api.github.com/users/ipfs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ipfs/subscriptions","organizations_url":"https://api.github.com/users/ipfs/orgs","repos_url":"https://api.github.com/users/ipfs/repos","events_url":"https://api.github.com/users/ipfs/events{/privacy}","received_events_url":"https://api.github.com/users/ipfs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ipfs/go-ipfs","description":"ipfs implementation in go","fork":false,"url":"https://api.github.com/repos/ipfs/go-ipfs","forks_url":"https://api.github.com/repos/ipfs/go-ipfs/forks","keys_url":"https://api.github.com/repos/ipfs/go-ipfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ipfs/go-ipfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ipfs/go-ipfs/teams","hooks_url":"https://api.github.com/repos/ipfs/go-ipfs/hooks","issue_events_url":"https://api.github.com/repos/ipfs/go-ipfs/issues/events{/number}","events_url":"https://api.github.com/repos/ipfs/go-ipfs/events","assignees_url":"https://api.github.com/repos/ipfs/go-ipfs/assignees{/user}","branches_url":"https://api.github.com/repos/ipfs/go-ipfs/branches{/branch}","tags_url":"https://api.github.com/repos/ipfs/go-ipfs/tags","blobs_url":"https://api.github.com/repos/ipfs/go-ipfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ipfs/go-ipfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ipfs/go-ipfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/ipfs/go-ipfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ipfs/go-ipfs/statuses/{sha}","languages_url":"https://api.github.com/repos/ipfs/go-ipfs/languages","stargazers_url":"https://api.github.com/repos/ipfs/go-ipfs/stargazers","contributors_url":"https://api.github.com/repos/ipfs/go-ipfs/contributors","subscribers_url":"https://api.github.com/repos/ipfs/go-ipfs/subscribers","subscription_url":"https://api.github.com/repos/ipfs/go-ipfs/subscription","commits_url":"https://api.github.com/repos/ipfs/go-ipfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/ipfs/go-ipfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/ipfs/go-ipfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/ipfs/go-ipfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/ipfs/go-ipfs/contents/{+path}","compare_url":"https://api.github.com/repos/ipfs/go-ipfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ipfs/go-ipfs/merges","archive_url":"https://api.github.com/repos/ipfs/go-ipfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ipfs/go-ipfs/downloads","issues_url":"https://api.github.com/repos/ipfs/go-ipfs/issues{/number}","pulls_url":"https://api.github.com/repos/ipfs/go-ipfs/pulls{/number}","milestones_url":"https://api.github.com/repos/ipfs/go-ipfs/milestones{/number}","notifications_url":"https://api.github.com/repos/ipfs/go-ipfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ipfs/go-ipfs/labels{/name}","releases_url":"https://api.github.com/repos/ipfs/go-ipfs/releases{/id}","created_at":"2014-06-26T08:14:34Z","updated_at":"2015-07-19T05:53:57Z","pushed_at":"2015-07-20T05:19:12Z","git_url":"git://github.com/ipfs/go-ipfs.git","ssh_url":"git@github.com:ipfs/go-ipfs.git","clone_url":"https://github.com/ipfs/go-ipfs.git","svn_url":"https://github.com/ipfs/go-ipfs","homepage":"https://github.com/ipfs/ipfs","size":33517,"stargazers_count":641,"watchers_count":641,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":113,"mirror_url":null,"open_issues_count":301,"forks":113,"open_issues":301,"watchers":641,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ipfs/go-ipfs/pulls/1495"},"html":{"href":"https://github.com/ipfs/go-ipfs/pull/1495"},"issue":{"href":"https://api.github.com/repos/ipfs/go-ipfs/issues/1495"},"comments":{"href":"https://api.github.com/repos/ipfs/go-ipfs/issues/1495/comments"},"review_comments":{"href":"https://api.github.com/repos/ipfs/go-ipfs/pulls/1495/comments"},"review_comment":{"href":"https://api.github.com/repos/ipfs/go-ipfs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ipfs/go-ipfs/pulls/1495/commits"},"statuses":{"href":"https://api.github.com/repos/ipfs/go-ipfs/statuses/7ed7f35969a16b100f26d4134d6243ad26ecf23b"}}}}