Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Add multi store APIs #293

Closed
wants to merge 1 commit into from
Closed

Conversation

ing-eoking
Copy link
Collaborator

@ing-eoking ing-eoking commented Jul 15, 2024

๐Ÿ”— Related Issue

  • jam2in/arcus-works#589

โŒจ๏ธ What I did

  • store ๊ด€๋ จ bulk ๋ช…๋ น์–ด ์ˆ˜ํ–‰์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
    • set, add, replace, append, prepend, cas
    • store ๊ด€๋ จ ๋ช…๋ น์–ด send ๊ณผ์ •์—์„œ response๋ฅผ ๋‚˜์ค‘์— ํ•œ๋ฒˆ์— ์ฒ˜๋ฆฌํ•˜๋Š” memcached_send_bulk๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿค” Others

  • delete, incr, decr ๊ด€๋ จ multi ๋ช…๋ น์–ด๋Š” store๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ๋ชจ๋“ˆ์— ์žˆ์–ด ๋ณ„๋„์˜ PR๋กœ ์˜ฌ๋ฆด ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.
  • Memcached::Fast::Safe ์—์„œ flag ๊ฐ’์€ ๋ชจ๋‘ 0์œผ๋กœ ์„ค์ •๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.
    • bulk ๋ช…๋ น์–ด ๋‚ด ๋ชจ๋“  ๋ช…๋ น์€ ๋ชจ๋‘ ๋™์ผํ•œ ํ”Œ๋ž˜๊ทธ๊ฐ’์„ ๊ฐ–์Šต๋‹ˆ๋‹ค.

@ing-eoking ing-eoking marked this pull request as draft July 15, 2024 05:46
@ing-eoking ing-eoking requested a review from namsic July 15, 2024 05:58
@ing-eoking ing-eoking marked this pull request as ready for review July 15, 2024 07:00
@ing-eoking
Copy link
Collaborator Author

ing-eoking commented Jul 15, 2024

ํ™œ์šฉ ์˜ˆ์ œ

  • ์ฝ”๋“œ
#include "config.hpp"
#include <iostream>
#include <map>

#include "libmemcached/memcached.h"

using namespace std;

#define MAX_NUMBER 7

memcached_st *mc;

bool mc_init() {
    mc = memcached_create(NULL);
    if (mc == NULL) return false;
    //if (MEMCACHED_SUCCESS != memcached_server_add(mc, "127.0.0.1", 54321))
    if (MEMCACHED_SUCCESS != arcus_connect(mc, "127.0.0.1:2181", "test"))
        return true;
    return false;
}

int main(int argc, char **argv) {
    if (mc_init()) return -1;

    uint32_t flags= 10;
    vector< pair<string, string> > kv;
    vector<const char *> keys, values;
    vector<size_t> keys_length, values_length;

    for (int i = 0; i < MAX_NUMBER; i++)
        kv.push_back(make_pair("key" + to_string(i), to_string(i)));

    for (int i = 0; i < MAX_NUMBER; i++) {
        keys.push_back(kv[i].first.c_str());
        keys_length.push_back(kv[i].first.length());
        values.push_back(kv[i].second.c_str());
        values_length.push_back(kv[i].second.length());
    }

    vector<memcached_return_t> results(MAX_NUMBER);
    memcached_set_bulk(mc, (char **)(&keys[0]),   (size_t *)(&keys_length[0]), MAX_NUMBER,
                           (char **)(&values[0]), (size_t *)(&values_length[0]), NULL, flags,
                           (memcached_return_t *)(&results[0]));
    for (int i = 0; i < MAX_NUMBER; i++)
        cout << string(keys[i]) << " : " << memcached_strerror(mc, results[i]) << endl;

    return 0;
}
  • ๊ฒฐ๊ณผ
    • ๋ชจ๋‘ ์„ฑ๊ณตํ•œ ๊ฒฝ์šฐ
    key0 : STORED
    key1 : STORED
    key2 : STORED
    key3 : STORED
    key4 : STORED
    key5 : STORED
    key6 : STORED
    
    • ์ค‘๊ฐ„์— ์—๋Ÿฌ ๋ฐœ์ƒ(key3์— ๋Œ€ํ•˜์—ฌ TYPE_MISMATCH ์—๋Ÿฌ ๊ฐ•์ œ ๋ฐœ์ƒ)
    key0 : STORED
    key1 : STORED
    key2 : STORED
    key3 : COLLECTION TYPE MISMATCH
    key4 : STORED
    key5 : STORED
    key6 : STORED
    

@ing-eoking ing-eoking self-assigned this Jul 15, 2024
@ing-eoking ing-eoking requested a review from uhm0311 July 15, 2024 08:22
libmemcached/storage.cc Outdated Show resolved Hide resolved
libmemcached/storage.cc Outdated Show resolved Hide resolved
@ing-eoking ing-eoking force-pushed the multi branch 2 times, most recently from a07ebb7 to e49850d Compare July 16, 2024 01:34
@ing-eoking ing-eoking requested a review from namsic July 16, 2024 01:35
@ing-eoking ing-eoking force-pushed the multi branch 2 times, most recently from a2f9657 to 2442aac Compare July 16, 2024 01:58
libmemcached/storage.cc Outdated Show resolved Hide resolved
libmemcached/storage.cc Outdated Show resolved Hide resolved
@ing-eoking ing-eoking force-pushed the multi branch 3 times, most recently from 9e7a03a to 36ef96b Compare July 16, 2024 09:46
@ing-eoking ing-eoking force-pushed the multi branch 2 times, most recently from c295951 to 873cdfe Compare July 17, 2024 02:16
@ing-eoking ing-eoking marked this pull request as draft July 17, 2024 02:30
@ing-eoking ing-eoking force-pushed the multi branch 4 times, most recently from 7bd4c60 to e9ccc39 Compare July 17, 2024 09:02
@namsic namsic self-requested a review July 17, 2024 09:40
@ing-eoking ing-eoking force-pushed the multi branch 2 times, most recently from f6287ed to 08ceedb Compare July 17, 2024 23:45
@ing-eoking ing-eoking marked this pull request as ready for review July 17, 2024 23:47
@ing-eoking ing-eoking marked this pull request as draft July 18, 2024 01:44
@ing-eoking ing-eoking marked this pull request as ready for review July 18, 2024 02:57
@ing-eoking ing-eoking marked this pull request as draft July 18, 2024 03:05
@ing-eoking ing-eoking force-pushed the multi branch 2 times, most recently from 9ec1610 to 6eabe16 Compare July 18, 2024 03:13
@ing-eoking ing-eoking marked this pull request as ready for review July 18, 2024 04:55
Comment on lines +486 to +489
else if (verb == CAS_OP and cas[i] == 0)
{
results[i] = MEMCACHED_PROTOCOL_ERROR;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ์กฐ๊ฑด๋ฌธ์ด ์—†์œผ๋ฉด ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•˜๊ฒŒ ๋˜๋‚˜์š”?

Copy link
Collaborator Author

@ing-eoking ing-eoking Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C-Client ๋‚ด๋ถ€์ ์œผ๋กœ cas๊ฐ€ 0์ธ ๊ฒฝ์šฐ cas๋ฅผ ์ œ์™ธํ•˜๊ณ  ๋ณด๋‚ด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
๊ทธ๋Ÿฌ๋ฏ€๋กœ ์„œ๋ฒ„๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ๋ณด๋‚ด๊ฒŒ ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

cas i 0 0 1
1

์ด ๊ฒฝ์šฐ ์„œ๋ฒ„๋Š” ERROR no matching command ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ๋˜๋ฉฐ,
PROTOCOL_ERROR ์ดํ›„ reconnect๋กœ ์ธํ•œ CONNECTION_FAILURE๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—ฌ๊ธฐ์„œ ํ™•์ธํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cas ๊ฐ’ ๊ฒ€์‚ฌ๋Š” ์•„๋ž˜ ํ•จ์ˆ˜์—์„œ ์ˆ˜ํ–‰ํ•ฉ์‹œ๋‹ค.

  • memcached_cas()
  • memcached_cas_bulk()

@jhpark816
Copy link
Contributor

@namsic approveํ•œ ์ƒํƒœ์ธ๊ฐ€์š”?

@namsic
Copy link
Collaborator

namsic commented Jul 20, 2024

@jhpark816 approve ์ดํ›„ ์ˆ˜์ •์ด ์žˆ์–ด์„œ, ๋‹ค์‹œ ํ™•์ธ ์ค‘์ž…๋‹ˆ๋‹ค.

@jhpark816 jhpark816 requested a review from namsic July 21, 2024 05:33
Copy link
Contributor

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ผ๋ถ€ ๋ฆฌ๋ทฐ

return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT,
memcached_literal_param("value (length) list is null"));
}
if (verb == CAS_OP and not cas){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ ๋ฌธ์ž๋Š” ๋‹ค์Œ ๋ผ์ธ์—์„œ ์‹œ์ž‘

Comment on lines +486 to +489
else if (verb == CAS_OP and cas[i] == 0)
{
results[i] = MEMCACHED_PROTOCOL_ERROR;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cas ๊ฐ’ ๊ฒ€์‚ฌ๋Š” ์•„๋ž˜ ํ•จ์ˆ˜์—์„œ ์ˆ˜ํ–‰ํ•ฉ์‹œ๋‹ค.

  • memcached_cas()
  • memcached_cas_bulk()

return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT,
memcached_literal_param("result is null"));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ์œ„์น˜์—์„œ memcached_key_test() ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ์ด ๋งž์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

@@ -605,3 +700,92 @@ memcached_return_t memcached_cas_by_key(memcached_st *ptr,
return rc;
}

memcached_return_t memcached_set_bulk(memcached_st *ptr,
const char * const *keys, const size_t *key_length,
size_t number_of_keys,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

number_of_keys ๋ณด๋‹ค๋Š” keys ์ธ์ž ์•ž์— bulk_count ๋‘๋Š” ๊ฒƒ์ด ๋งž์ง€ ์•Š๋Š” ์ง€ ?

expirations ? expirations[i] : 0, flags,
cas ? cas[i] : 0, verb);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memcached_send_bulk_ascii() ํ•จ์ˆ˜๋ฅผ ๋ณ„๋„๋กœ ๋‘๋Š” ๋ฐฉ์•ˆ๋„ ๊ฒ€ํ† ํ•ด ๋ณด์•˜๋‚˜์š”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฒ€ํ†  ๊ฒฐ๊ณผ memcached_send_ascii์™€ response ๋ถ€๋ถ„์„ ์ œ์™ธํ•œ ๋งŽ์€ ๋กœ์ง์ด ์ผ์น˜ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
(Validation ๊ฒ€์‚ฌ, ๋ช…๋ น์–ด ๋ฒกํ„ฐ ๊ตฌ์„ฑ)

๊ทธ๋ž˜์„œ ์ƒˆ๋กœ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค๋Š” memcached_send_ascii๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ์•ˆ์ด ๋‚ซ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.

@ing-eoking ing-eoking marked this pull request as draft July 22, 2024 05:21
@ing-eoking
Copy link
Collaborator Author

ํ•ด๋‹น ์ž‘์—…์€ @uhm0311 ์ด ํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ PR ๋‹ซ๊ฒ ์Šต๋‹ˆ๋‹ค.

@ing-eoking ing-eoking closed this Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants