<commit_before>field_count = 10
timeout = 0.05

function increment_or_insert(space, key, field)
    retry = true
    while retry do
	    status, result = pcall(box.update, space, key, '+p', field, 1)
	if status then
	--success update or tuple is not exist
	    retry = false
	    if result == nil then
            --insert new tuple
            tuple = {}
            for i = 2, field_count do tuple[i] = 0 end
                tuple[1] = os.date("%d_%m_%y")
                tuple[tonumber(field)] = 1
                box.insert(space, key, unpack(tuple))
            end
        else
        --exception
            if result == "Tuple is marked as read-only" then
                box.fiber.sleep(timeout)
            else
                retry = false
                print("space="..space.." key="..key.." field="..field.." :"..result)
            end
        end
    end
end<commit_msg>fix date, add logging, max attempts<commit_after>field_count = 10
timeout = 0.006
max_attempts = 5

function increment_or_insert(space, key, field)
    retry = true
    count = 0
    while retry do
	status, result = pcall(box.update, space, key, '+p', field, 1)
	if status then
	--success update or tuple is not exist
	    retry = false
	    if result == nil then
	    --insert new tuple
		tuple = {}
		for i = 2, field_count do tuple[i] = 0 end
		tuple[1] = string.sub(key, -8)
		tuple[tonumber(field)] = 1
		box.insert(space, key, unpack(tuple))
	    end
	else
	--exception
	    count = count + 1
	    if count == max_attempts then
		print("max attempts reached for space="..space.." key="..key.." field="..field)
		break
	    end
	    box.fiber.sleep(timeout)
	end
    end
end
{'fraction_non_alphanumeric': 0.11750599520383694, 'fraction_numerical': 0.01498800959232614, 'mean_word_length': 1.9856887298747763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6460736', 'n_tokens_mistral': 562, 'n_tokens_neox': 511, 'n_words': 167}