)]}'
{"/COMMIT_MSG":[{"author":{"_account_id":6788,"name":"Rossella Sblendido","email":"rsblendido@suse.com","username":"rossella-o"},"change_message_id":"dabfb41b566eda3698fdba0e70ce713ae72f2f15","unresolved":false,"context_lines":[{"line_number":11,"context_line":"  for count in range(...):"},{"line_number":12,"context_line":"    try:"},{"line_number":13,"context_line":"      \u003cselect allocated vrids\u003e"},{"line_number":14,"context_line":"      \u003ctry to allocate a non-allocated vrid and return it\u003e"},{"line_number":15,"context_line":"    except DBDuplicateEntry:"},{"line_number":16,"context_line":"      pass"},{"line_number":17,"context_line":""}],"source_content_type":"text/x-gerrit-commit-message","patch_set":2,"id":"9a8ffd7b_e5794783","line":14,"updated":"2015-11-27 12:54:11.000000000","message":"I\u0027d rephrase \"try to allocate the first non-allocated vrid\"","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":6788,"name":"Rossella Sblendido","email":"rsblendido@suse.com","username":"rossella-o"},"change_message_id":"dabfb41b566eda3698fdba0e70ce713ae72f2f15","unresolved":false,"context_lines":[{"line_number":16,"context_line":"      pass"},{"line_number":17,"context_line":""},{"line_number":18,"context_line":"The select returns the same values over iterations because of REPEATABLE"},{"line_number":19,"context_line":"READ transactions and every iteration will try to allocate the same"},{"line_number":20,"context_line":"vrid."},{"line_number":21,"context_line":""},{"line_number":22,"context_line":"This change corrects _allocate_vr_id by trying to allocate remaining"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":2,"id":"9a8ffd7b_453373ab","line":19,"updated":"2015-11-27 12:54:11.000000000","message":"I think it would be more clear:\n\n\"The select returns the same list of values over iterations because of REPEATABLE READ. As a result the code will pop the same values in the same order and try to allocate the same vrid every time.\"","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":6788,"name":"Rossella Sblendido","email":"rsblendido@suse.com","username":"rossella-o"},"change_message_id":"dabfb41b566eda3698fdba0e70ce713ae72f2f15","unresolved":false,"context_lines":[{"line_number":19,"context_line":"READ transactions and every iteration will try to allocate the same"},{"line_number":20,"context_line":"vrid."},{"line_number":21,"context_line":""},{"line_number":22,"context_line":"This change corrects _allocate_vr_id by trying to allocate remaining"},{"line_number":23,"context_line":"non-allocated vrids randomly."},{"line_number":24,"context_line":""},{"line_number":25,"context_line":"Closes-Bug: #1520152"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":2,"id":"9a8ffd7b_c5cd2386","line":22,"updated":"2015-11-27 12:54:11.000000000","message":"You are also using the same list of values, you don\u0027t get a new list for every iteration.","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"}],"neutron/db/l3_hamode_db.py":[{"author":{"_account_id":6788,"name":"Rossella Sblendido","email":"rsblendido@suse.com","username":"rossella-o"},"change_message_id":"f553f626f3b439123e5c47d9a77feb4b101cace9","unresolved":false,"context_lines":[{"line_number":185,"context_line":"        return allocated_vr_ids"},{"line_number":186,"context_line":""},{"line_number":187,"context_line":"    def _allocate_vr_id(self, context, network_id, router_id):"},{"line_number":188,"context_line":"        allocated_vr_ids \u003d self._get_allocated_vr_id(context, network_id)"},{"line_number":189,"context_line":"        available_vr_ids \u003d list(VR_ID_RANGE - allocated_vr_ids)"},{"line_number":190,"context_line":"        random.shuffle(available_vr_ids)"},{"line_number":191,"context_line":"        for count in range(MAX_ALLOCATION_TRIES):"}],"source_content_type":"text/x-python","patch_set":2,"id":"9a8ffd7b_bea8498d","line":188,"updated":"2015-11-26 18:42:04.000000000","message":"these lines should be moved after line 191, otherwise we get the same problem we are trying to fix :P","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":6788,"name":"Rossella Sblendido","email":"rsblendido@suse.com","username":"rossella-o"},"change_message_id":"dabfb41b566eda3698fdba0e70ce713ae72f2f15","unresolved":false,"context_lines":[{"line_number":185,"context_line":"        return allocated_vr_ids"},{"line_number":186,"context_line":""},{"line_number":187,"context_line":"    def _allocate_vr_id(self, context, network_id, router_id):"},{"line_number":188,"context_line":"        allocated_vr_ids \u003d self._get_allocated_vr_id(context, network_id)"},{"line_number":189,"context_line":"        available_vr_ids \u003d list(VR_ID_RANGE - allocated_vr_ids)"},{"line_number":190,"context_line":"        random.shuffle(available_vr_ids)"},{"line_number":191,"context_line":"        for count in range(MAX_ALLOCATION_TRIES):"}],"source_content_type":"text/x-python","patch_set":2,"id":"9a8ffd7b_e28862c7","line":188,"in_reply_to":"9a8ffd7b_9e3ea526","updated":"2015-11-27 12:54:11.000000000","message":"OK got it now. So I wonder, do we really need to shuffle the results? If I understand correctly, before this change the pop at line 198 was returning always the same ID, now since these lines are out for the for loop, the pop will act on the same list and get the next ID in the list, not always the same one.","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":8124,"name":"cbrandily","email":"zzelle@gmail.com","username":"cbrandily"},"change_message_id":"c701ae9026c52fcc88c958b8154cd55341ba4550","unresolved":false,"context_lines":[{"line_number":185,"context_line":"        return allocated_vr_ids"},{"line_number":186,"context_line":""},{"line_number":187,"context_line":"    def _allocate_vr_id(self, context, network_id, router_id):"},{"line_number":188,"context_line":"        allocated_vr_ids \u003d self._get_allocated_vr_id(context, network_id)"},{"line_number":189,"context_line":"        available_vr_ids \u003d list(VR_ID_RANGE - allocated_vr_ids)"},{"line_number":190,"context_line":"        random.shuffle(available_vr_ids)"},{"line_number":191,"context_line":"        for count in range(MAX_ALLOCATION_TRIES):"}],"source_content_type":"text/x-python","patch_set":2,"id":"9a8ffd7b_9e3ea526","line":188,"in_reply_to":"9a8ffd7b_bea8498d","updated":"2015-11-26 19:01:04.000000000","message":"We already are in a transaction (L222) so if we move the select after L191 we will get the same result over and over","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":8124,"name":"cbrandily","email":"zzelle@gmail.com","username":"cbrandily"},"change_message_id":"3470e8acaa1e97b6ff2f73e62d0e2c989345fe3e","unresolved":false,"context_lines":[{"line_number":185,"context_line":"        return allocated_vr_ids"},{"line_number":186,"context_line":""},{"line_number":187,"context_line":"    def _allocate_vr_id(self, context, network_id, router_id):"},{"line_number":188,"context_line":"        allocated_vr_ids \u003d self._get_allocated_vr_id(context, network_id)"},{"line_number":189,"context_line":"        available_vr_ids \u003d list(VR_ID_RANGE - allocated_vr_ids)"},{"line_number":190,"context_line":"        random.shuffle(available_vr_ids)"},{"line_number":191,"context_line":"        for count in range(MAX_ALLOCATION_TRIES):"}],"source_content_type":"text/x-python","patch_set":2,"id":"9a8ffd7b_ecb27d4b","line":188,"in_reply_to":"9a8ffd7b_e28862c7","updated":"2015-11-27 19:35:52.000000000","message":"random.shuffle avoids in general concurrent _allocate_vr_ids to visit unallocated vrids in the same order and reduces the average number of iterations before allocating a vrid.","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"365ba269de5051e245b3683f4c472964d1fe16d9","unresolved":false,"context_lines":[{"line_number":187,"context_line":"    def _allocate_vr_id(self, context, network_id, router_id):"},{"line_number":188,"context_line":"        allocated_vr_ids \u003d self._get_allocated_vr_id(context, network_id)"},{"line_number":189,"context_line":"        available_vr_ids \u003d list(VR_ID_RANGE - allocated_vr_ids)"},{"line_number":190,"context_line":"        random.shuffle(available_vr_ids)"},{"line_number":191,"context_line":"        for count in range(MAX_ALLOCATION_TRIES):"},{"line_number":192,"context_line":"            if not available_vr_ids:"},{"line_number":193,"context_line":"                raise l3_ha.NoVRIDAvailable(router_id\u003drouter_id)"}],"source_content_type":"text/x-python","patch_set":2,"id":"5a710552_8f48f588","line":190,"updated":"2015-12-16 07:36:11.000000000","message":"Can this patch reduce the race in vr id allocation? What will happen when multiple API calls come here? Why don\u0027t put random.shuffle in \u0027for count in range(MAX_ALLOCATION_TRIES)\u0027 to avoid pop the same vr id?","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":8124,"name":"cbrandily","email":"zzelle@gmail.com","username":"cbrandily"},"change_message_id":"ff7b338ea8bc9c7c159914add99b42dc814275c4","unresolved":false,"context_lines":[{"line_number":187,"context_line":"    def _allocate_vr_id(self, context, network_id, router_id):"},{"line_number":188,"context_line":"        allocated_vr_ids \u003d self._get_allocated_vr_id(context, network_id)"},{"line_number":189,"context_line":"        available_vr_ids \u003d list(VR_ID_RANGE - allocated_vr_ids)"},{"line_number":190,"context_line":"        random.shuffle(available_vr_ids)"},{"line_number":191,"context_line":"        for count in range(MAX_ALLOCATION_TRIES):"},{"line_number":192,"context_line":"            if not available_vr_ids:"},{"line_number":193,"context_line":"                raise l3_ha.NoVRIDAvailable(router_id\u003drouter_id)"}],"source_content_type":"text/x-python","patch_set":2,"id":"1a7b0d38_c4dd9215","line":190,"in_reply_to":"5a710552_8f48f588","updated":"2015-12-24 13:27:52.000000000","message":"The aim of the random.shuffle is to ensure concurrent calls will try to allocate available vr_ids in different orders in general. Doing it in the for loop is costly and overkill as a unique shuffle is enough to ensure different ordering in general because:\n\n len(VR_IR_RANGE) \u003e\u003e len(allocated_vr_ids) ~ max_l3_agents_per_router","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":6788,"name":"Rossella Sblendido","email":"rsblendido@suse.com","username":"rossella-o"},"change_message_id":"f553f626f3b439123e5c47d9a77feb4b101cace9","unresolved":false,"context_lines":[{"line_number":192,"context_line":"            if not available_vr_ids:"},{"line_number":193,"context_line":"                raise l3_ha.NoVRIDAvailable(router_id\u003drouter_id)"},{"line_number":194,"context_line":"            try:"},{"line_number":195,"context_line":"                with context.session.begin(nested\u003dTrue):"},{"line_number":196,"context_line":"                    allocation \u003d L3HARouterVRIdAllocation()"},{"line_number":197,"context_line":"                    allocation.network_id \u003d network_id"},{"line_number":198,"context_line":"                    allocation.vr_id \u003d available_vr_ids.pop()"}],"source_content_type":"text/x-python","patch_set":2,"id":"9a8ffd7b_febb31e3","line":195,"updated":"2015-11-26 18:42:04.000000000","message":"I am not sure this will start a brand new transaction since there\u0027s already a transaction open and it\u0027s passed in the session object, see discussion here [1] , maybe you can use the oslo db wrap_db_retry decorator to solve this?\n\n[1] https://review.openstack.org/#/c/149261/10/neutron/plugins/ml2/drivers/helpers.py","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":8124,"name":"cbrandily","email":"zzelle@gmail.com","username":"cbrandily"},"change_message_id":"c701ae9026c52fcc88c958b8154cd55341ba4550","unresolved":false,"context_lines":[{"line_number":192,"context_line":"            if not available_vr_ids:"},{"line_number":193,"context_line":"                raise l3_ha.NoVRIDAvailable(router_id\u003drouter_id)"},{"line_number":194,"context_line":"            try:"},{"line_number":195,"context_line":"                with context.session.begin(nested\u003dTrue):"},{"line_number":196,"context_line":"                    allocation \u003d L3HARouterVRIdAllocation()"},{"line_number":197,"context_line":"                    allocation.network_id \u003d network_id"},{"line_number":198,"context_line":"                    allocation.vr_id \u003d available_vr_ids.pop()"}],"source_content_type":"text/x-python","patch_set":2,"id":"9a8ffd7b_1e6ab5ee","line":195,"in_reply_to":"9a8ffd7b_febb31e3","updated":"2015-11-26 19:01:04.000000000","message":"It seems:\n\n len(VR_IR_RANGE) \u003e\u003e len(allocated_vr_ids) ~ max_l3_agents_per_router\n\nso imo there is no need to raise a RetryError when we have a \"lot\" of candidates.","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"},{"author":{"_account_id":9531,"name":"liuyulong","display_name":"LIU Yulong","email":"i@liuyulong.me","username":"LIU-Yulong"},"change_message_id":"365ba269de5051e245b3683f4c472964d1fe16d9","unresolved":false,"context_lines":[{"line_number":217,"context_line":"                network_id\u003dha_network.network_id,"},{"line_number":218,"context_line":"                vr_id\u003dvr_id).delete()"},{"line_number":219,"context_line":""},{"line_number":220,"context_line":"    def _set_vr_id(self, context, router, ha_network):"},{"line_number":221,"context_line":"        with context.session.begin(nested\u003dTrue):"},{"line_number":222,"context_line":"            router.extra_attributes.ha_vr_id \u003d self._allocate_vr_id("},{"line_number":223,"context_line":"                context, ha_network.network_id, router.id)"}],"source_content_type":"text/x-python","patch_set":2,"id":"5a710552_92b81ee7","line":220,"updated":"2015-12-16 07:36:11.000000000","message":"If this patch were rebased, the session begin here was removed. And then vr id allocation retry will get the correct used vr id list which means the available_vr_ids are not same each time.","commit_id":"bf6c2f776a6f0d364e015303617502245244f1b9"}]}
