You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/09/21 00:28:14 UTC
[1/2] git commit: [#6695] Added timeout for computing LCDs to prevent
hung requests
Updated Branches:
refs/heads/cj/6695 [created] f77723602
[#6695] Added timeout for computing LCDs to prevent hung requests
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/98cf88dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/98cf88dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/98cf88dd
Branch: refs/heads/cj/6695
Commit: 98cf88ddf3031130085d615b8dc4f5889f11a760
Parents: d83c5c2
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Fri Sep 20 21:23:44 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Fri Sep 20 22:23:09 2013 +0000
----------------------------------------------------------------------
Allura/allura/model/repo.py | 5 +++--
Allura/allura/model/repository.py | 7 ++++++-
Allura/allura/tests/model/test_repo.py | 15 +++++++++++++++
3 files changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/98cf88dd/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index 06a0853..502961b 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -843,8 +843,9 @@ class LastCommit(RepoObject):
# (but only ask for the ones that we know we need)
entries = tree.commit.repo.last_commit_ids(tree.commit, unchanged)
if entries is None:
- # something strange went wrong; bail out and possibly try again later
- return None
+ # something strange went wrong; still show the list of files
+ # and possibly try again later
+ entries = {}
# paths are fully-qualified; shorten them back to just node names
entries = {os.path.basename(path):commit_id for path,commit_id in entries.iteritems()}
# update with the nodes changed in this tree's commit
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/98cf88dd/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 3fe5a80..32b9bf1 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -27,13 +27,14 @@ from subprocess import Popen, PIPE
from difflib import SequenceMatcher
from hashlib import sha1
from datetime import datetime
+from time import time
from collections import defaultdict
from itertools import izip
from urlparse import urljoin
from urllib import quote
import tg
-from paste.deploy.converters import asbool
+from paste.deploy.converters import asbool, asint
from pylons import tmpl_context as c
from pylons import app_globals as g
import pymongo.errors
@@ -144,9 +145,13 @@ class RepositoryImplementation(object):
Return a mapping {path: commit_id} of the _id of the last
commit to touch each path, starting from the given commit.
'''
+ timeout = asint(config.get('lcd_timeout', 60)) * 1000
+ start_time = time()
paths = set(paths)
result = {}
while paths and commit:
+ if time() - start_time > timeout:
+ return result
changed = paths & set(commit.changed_paths)
result.update({path: commit._id for path in changed})
paths = paths - changed
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/98cf88dd/Allura/allura/tests/model/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index 5d9e95e..b67be9f 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -17,15 +17,18 @@
from datetime import datetime
from collections import defaultdict, OrderedDict
+
import unittest
import mock
from nose.tools import assert_equal
from pylons import tmpl_context as c
from bson import ObjectId
from ming.orm import session
+from tg import config
from alluratest.controller import setup_basic_test, setup_global_objects
from allura import model as M
+from allura.lib import helpers as h
class TestGitLikeTree(object):
@@ -319,6 +322,18 @@ class TestLastCommit(unittest.TestCase):
result = self.repo.last_commit_ids(commit1, ['file1'])
assert_equal(result, {'file1': commit1._id})
+ def test_timeout(self):
+ commit1 = self._add_commit('Commit 1', ['file1'])
+ commit2 = self._add_commit('Commit 2', ['file1', 'dir1/file1'], ['dir1/file1'], [commit1])
+ commit3 = self._add_commit('Commit 3', ['file1', 'dir1/file1', 'file2'], ['file2'], [commit2])
+ with h.push_config(config, lcd_timeout=0):
+ lcd = M.repo.LastCommit.get(commit3.tree)
+ self.assertEqual(self.repo._commits[lcd.commit_id].message, commit3.message)
+ self.assertEqual(lcd.commit_id, commit3._id)
+ self.assertEqual(lcd.path, '')
+ self.assertEqual(len(lcd.entries), 1)
+ self.assertEqual(lcd.by_name['file2'], commit3._id)
+
class TestModelCache(unittest.TestCase):
def setUp(self):
[2/2] git commit: [#6695] Added sanity check in LCD for loops in
commit data
Posted by jo...@apache.org.
[#6695] Added sanity check in LCD for loops in commit data
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/f7772360
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/f7772360
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/f7772360
Branch: refs/heads/cj/6695
Commit: f777236027fb3e7fde28a854c33d16373de59447
Parents: 98cf88d
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Fri Sep 20 22:27:25 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Fri Sep 20 22:27:34 2013 +0000
----------------------------------------------------------------------
Allura/allura/model/repository.py | 4 ++++
Allura/allura/tests/model/test_repo.py | 14 ++++++++++++++
2 files changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f7772360/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 32b9bf1..b371295 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -149,9 +149,13 @@ class RepositoryImplementation(object):
start_time = time()
paths = set(paths)
result = {}
+ seen_commits = set()
while paths and commit:
if time() - start_time > timeout:
return result
+ if commit._id in seen_commits:
+ return result # sanity check for bad data (loops)
+ seen_commits.add(commit._id)
changed = paths & set(commit.changed_paths)
result.update({path: commit._id for path in changed})
paths = paths - changed
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f7772360/Allura/allura/tests/model/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index b67be9f..ef39e4b 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -334,6 +334,20 @@ class TestLastCommit(unittest.TestCase):
self.assertEqual(len(lcd.entries), 1)
self.assertEqual(lcd.by_name['file2'], commit3._id)
+ def test_loop(self):
+ commit1 = self._add_commit('Commit 1', ['file1'])
+ commit2 = self._add_commit('Commit 2', ['file1', 'dir1/file1'], ['dir1/file1'], [commit1])
+ commit3 = self._add_commit('Commit 3', ['file1', 'dir1/file1', 'file2'], ['file2'], [commit2])
+ commit2.parent_ids = [commit3._id]
+ session(commit2).flush(commit2)
+ lcd = M.repo.LastCommit.get(commit3.tree)
+ self.assertEqual(self.repo._commits[lcd.commit_id].message, commit3.message)
+ self.assertEqual(lcd.commit_id, commit3._id)
+ self.assertEqual(lcd.path, '')
+ self.assertEqual(len(lcd.entries), 2)
+ self.assertEqual(lcd.by_name['dir1'], commit2._id)
+ self.assertEqual(lcd.by_name['file2'], commit3._id)
+
class TestModelCache(unittest.TestCase):
def setUp(self):