diff options
author | vskipin <vskipin@yandex-team.ru> | 2022-02-10 16:46:00 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:00 +0300 |
commit | 4d8b546b89b5afc08cf3667e176271c7ba935f33 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c | |
parent | 4e4b78bd7b67e2533da4dbb9696374a6d6068e32 (diff) | |
download | ydb-4d8b546b89b5afc08cf3667e176271c7ba935f33.tar.gz |
Restoring authorship annotation for <vskipin@yandex-team.ru>. Commit 2 of 2.
179 files changed, 7190 insertions, 7190 deletions
diff --git a/build/rules/contrib_restricted.policy b/build/rules/contrib_restricted.policy index 66d2734b7c..a83ead1904 100644 --- a/build/rules/contrib_restricted.policy +++ b/build/rules/contrib_restricted.policy @@ -179,9 +179,9 @@ ALLOW library/cpp/testing/gmock -> contrib/restricted/googletest/googlemock # allow usage of MIT part ALLOW .* -> contrib/restricted/librseq/headeronly -# we use nfs-ganesha for Network File Store gateway -ALLOW cloud/filestore/gateway/nfs -> contrib/restricted/nfs_ganesha - +# we use nfs-ganesha for Network File Store gateway +ALLOW cloud/filestore/gateway/nfs -> contrib/restricted/nfs_ganesha + ALLOW yandex_io -> contrib/restricted/patched/hostap_client # Default policies: diff --git a/build/sysincl/ibdrv.yml b/build/sysincl/ibdrv.yml index bfaa5e1177..5cf2c36078 100644 --- a/build/sysincl/ibdrv.yml +++ b/build/sysincl/ibdrv.yml @@ -6,7 +6,7 @@ - source_filter: "^contrib/libs/ibdrv" includes: - - infiniband/sa.h + - infiniband/sa.h - infiniband/verbs.h - - infiniband/verbs_api.h + - infiniband/verbs_api.h - rdma/rdma_cma.h diff --git a/build/sysincl/linux.yml b/build/sysincl/linux.yml index f95e728660..a92a09bb9c 100644 --- a/build/sysincl/linux.yml +++ b/build/sysincl/linux.yml @@ -6,7 +6,7 @@ - argp.h - argz.h - bfd.h - - bits/endian.h + - bits/endian.h - bits/fenv.h - bits/libc-lock.h - bits/reg.h diff --git a/build/sysincl/misc.yml b/build/sysincl/misc.yml index 9b1f15959a..e9e6095888 100644 --- a/build/sysincl/misc.yml +++ b/build/sysincl/misc.yml @@ -417,14 +417,14 @@ - nlist.h: contrib/restricted/libelf/lib/nlist.h - sys_elf.h: contrib/restricted/libelf/lib/sys_elf.h -- source_filter: "^contrib/libs/dpdk/" +- source_filter: "^contrib/libs/dpdk/" includes: - process.h: contrib/libs/dpdk/drivers/bus/dpaa/include/process.h -- source_filter: "^contrib/libs/dpdk_arm64/" - includes: - - process.h: contrib/libs/dpdk_arm64/drivers/bus/dpaa/include/process.h - +- source_filter: "^contrib/libs/dpdk_arm64/" + includes: + - process.h: contrib/libs/dpdk_arm64/drivers/bus/dpaa/include/process.h + - source_filter: "^contrib/libs/usrsctp/" includes: - netinet/sctp_uio.h: contrib/libs/usrsctp/usrsctplib/netinet/sctp_uio.h diff --git a/contrib/libs/grpc/src/core/lib/iomgr/executor.cc b/contrib/libs/grpc/src/core/lib/iomgr/executor.cc index 40e94b79c6..10b2f948ec 100644 --- a/contrib/libs/grpc/src/core/lib/iomgr/executor.cc +++ b/contrib/libs/grpc/src/core/lib/iomgr/executor.cc @@ -85,8 +85,8 @@ const EnqueueFunc {{default_enqueue_short, default_enqueue_long}, {resolver_enqueue_short, resolver_enqueue_long}}; -size_t threads_limit_ = 0; - +size_t threads_limit_ = 0; + } // namespace TraceFlag executor_trace(false, "executor"); @@ -95,17 +95,17 @@ Executor::Executor(const char* name) : name_(name) { adding_thread_lock_ = GPR_SPINLOCK_STATIC_INITIALIZER; gpr_atm_rel_store(&num_threads_, 0); max_threads_ = GPR_MAX(1, 2 * gpr_cpu_num_cores()); - if (threads_limit_) { - max_threads_ = GPR_MIN(max_threads_, threads_limit_); - } + if (threads_limit_) { + max_threads_ = GPR_MIN(max_threads_, threads_limit_); + } +} + +size_t Executor::SetThreadsLimit(size_t count) { + size_t prev = threads_limit_; + threads_limit_ = count; + return prev; } -size_t Executor::SetThreadsLimit(size_t count) { - size_t prev = threads_limit_; - threads_limit_ = count; - return prev; -} - void Executor::Init() { SetThreading(true); } size_t Executor::RunClosures(const char* executor_name, diff --git a/contrib/libs/grpc/src/core/lib/iomgr/executor.h b/contrib/libs/grpc/src/core/lib/iomgr/executor.h index 6a51e17532..ae523ff212 100644 --- a/contrib/libs/grpc/src/core/lib/iomgr/executor.h +++ b/contrib/libs/grpc/src/core/lib/iomgr/executor.h @@ -103,9 +103,9 @@ class Executor { // Return if the DEFAULT executor is threaded static bool IsThreadedDefault(); - // Set the maximum numbers of executor treads - static size_t SetThreadsLimit(size_t count); - + // Set the maximum numbers of executor treads + static size_t SetThreadsLimit(size_t count); + private: static size_t RunClosures(const char* executor_name, grpc_closure_list list); static void ThreadMain(void* arg); diff --git a/contrib/libs/libaio/io_cancel.c b/contrib/libs/libaio/io_cancel.c index 60f570fb8c..298751a6ec 100644 --- a/contrib/libs/libaio/io_cancel.c +++ b/contrib/libs/libaio/io_cancel.c @@ -1,22 +1,22 @@ -/* io_cancel.c - libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include "libaio.h" -#include "syscall.h" - +/* io_cancel.c + libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "libaio.h" +#include "syscall.h" + io_syscall3(int, io_cancel, io_cancel, io_context_t, ctx, struct iocb *, iocb, struct io_event *, event) diff --git a/contrib/libs/libaio/io_destroy.c b/contrib/libs/libaio/io_destroy.c index 39cec7cac7..ba28dd2ec9 100644 --- a/contrib/libs/libaio/io_destroy.c +++ b/contrib/libs/libaio/io_destroy.c @@ -1,23 +1,23 @@ -/* io_destroy - libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include <errno.h> -#include "libaio.h" -#include "syscall.h" - -io_syscall1(int, io_destroy, io_destroy, io_context_t, ctx) +/* io_destroy + libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <errno.h> +#include "libaio.h" +#include "syscall.h" + +io_syscall1(int, io_destroy, io_destroy, io_context_t, ctx) diff --git a/contrib/libs/libaio/io_getevents.c b/contrib/libs/libaio/io_getevents.c index 5791d1587d..b606e43283 100644 --- a/contrib/libs/libaio/io_getevents.c +++ b/contrib/libs/libaio/io_getevents.c @@ -1,56 +1,56 @@ -/* io_getevents.c - libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include "libaio.h" -#include <errno.h> -#include <stdlib.h> -#include <time.h> -#include "syscall.h" - -io_syscall5(int, __io_getevents_0_4, io_getevents, io_context_t, ctx, long, min_nr, long, nr, struct io_event *, events, struct timespec *, timeout) - -#define AIO_RING_MAGIC 0xa10a10a1 - -/* Ben will hate me for this */ -struct aio_ring { - unsigned id; /* kernel internal index number */ - unsigned nr; /* number of io_events */ - unsigned head; - unsigned tail; - - unsigned magic; - unsigned compat_features; - unsigned incompat_features; - unsigned header_length; /* size of aio_ring */ -}; - +/* io_getevents.c + libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "libaio.h" +#include <errno.h> +#include <stdlib.h> +#include <time.h> +#include "syscall.h" + +io_syscall5(int, __io_getevents_0_4, io_getevents, io_context_t, ctx, long, min_nr, long, nr, struct io_event *, events, struct timespec *, timeout) + +#define AIO_RING_MAGIC 0xa10a10a1 + +/* Ben will hate me for this */ +struct aio_ring { + unsigned id; /* kernel internal index number */ + unsigned nr; /* number of io_events */ + unsigned head; + unsigned tail; + + unsigned magic; + unsigned compat_features; + unsigned incompat_features; + unsigned header_length; /* size of aio_ring */ +}; + int io_getevents(io_context_t ctx, long min_nr, long nr, struct io_event * events, struct timespec * timeout) -{ - struct aio_ring *ring; - ring = (struct aio_ring*)ctx; - if (ring==NULL || ring->magic != AIO_RING_MAGIC) - goto do_syscall; - if (timeout!=NULL && timeout->tv_sec == 0 && timeout->tv_nsec == 0) { - if (ring->head == ring->tail) - return 0; - } - -do_syscall: - return __io_getevents_0_4(ctx, min_nr, nr, events, timeout); -} +{ + struct aio_ring *ring; + ring = (struct aio_ring*)ctx; + if (ring==NULL || ring->magic != AIO_RING_MAGIC) + goto do_syscall; + if (timeout!=NULL && timeout->tv_sec == 0 && timeout->tv_nsec == 0) { + if (ring->head == ring->tail) + return 0; + } + +do_syscall: + return __io_getevents_0_4(ctx, min_nr, nr, events, timeout); +} diff --git a/contrib/libs/libaio/io_queue_init.c b/contrib/libs/libaio/io_queue_init.c index 6f5c7d8799..62e8dc0335 100644 --- a/contrib/libs/libaio/io_queue_init.c +++ b/contrib/libs/libaio/io_queue_init.c @@ -1,33 +1,33 @@ -/* io_queue_init.c - libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include "libaio.h" -#include <sys/types.h> -#include <sys/stat.h> -#include <errno.h> - -#include "syscall.h" - -int io_queue_init(int maxevents, io_context_t *ctxp) -{ - if (maxevents > 0) { - *ctxp = NULL; - return io_setup(maxevents, ctxp); - } - return -EINVAL; -} +/* io_queue_init.c + libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "libaio.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> + +#include "syscall.h" + +int io_queue_init(int maxevents, io_context_t *ctxp) +{ + if (maxevents > 0) { + *ctxp = NULL; + return io_setup(maxevents, ctxp); + } + return -EINVAL; +} diff --git a/contrib/libs/libaio/io_queue_release.c b/contrib/libs/libaio/io_queue_release.c index 45fa150199..522d7651e4 100644 --- a/contrib/libs/libaio/io_queue_release.c +++ b/contrib/libs/libaio/io_queue_release.c @@ -1,27 +1,27 @@ -/* io_queue_release.c - libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include "libaio.h" -#include <sys/types.h> -#include <sys/stat.h> -#include <errno.h> - -int io_queue_release(io_context_t ctx) -{ - return io_destroy(ctx); -} +/* io_queue_release.c + libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "libaio.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> + +int io_queue_release(io_context_t ctx) +{ + return io_destroy(ctx); +} diff --git a/contrib/libs/libaio/io_queue_run.c b/contrib/libs/libaio/io_queue_run.c index 0b7244a8c8..3780ca093a 100644 --- a/contrib/libs/libaio/io_queue_run.c +++ b/contrib/libs/libaio/io_queue_run.c @@ -1,39 +1,39 @@ -/* io_submit - libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include "libaio.h" -#include <errno.h> -#include <stdlib.h> -#include <time.h> - -int io_queue_run(io_context_t ctx) -{ - static struct timespec timeout = { 0, 0 }; - struct io_event event; - int ret; - - /* FIXME: batch requests? */ - while (1 == (ret = io_getevents(ctx, 0, 1, &event, &timeout))) { - io_callback_t cb = (io_callback_t)event.data; - struct iocb *iocb = event.obj; - - cb(ctx, iocb, event.res, event.res2); - } - - return ret; -} +/* io_submit + libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "libaio.h" +#include <errno.h> +#include <stdlib.h> +#include <time.h> + +int io_queue_run(io_context_t ctx) +{ + static struct timespec timeout = { 0, 0 }; + struct io_event event; + int ret; + + /* FIXME: batch requests? */ + while (1 == (ret = io_getevents(ctx, 0, 1, &event, &timeout))) { + io_callback_t cb = (io_callback_t)event.data; + struct iocb *iocb = event.obj; + + cb(ctx, iocb, event.res, event.res2); + } + + return ret; +} diff --git a/contrib/libs/libaio/io_queue_wait.c b/contrib/libs/libaio/io_queue_wait.c index a4bf196ff0..e706901953 100644 --- a/contrib/libs/libaio/io_queue_wait.c +++ b/contrib/libs/libaio/io_queue_wait.c @@ -1,30 +1,30 @@ -/* io_submit - libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#define NO_SYSCALL_ERRNO -#include <sys/types.h> -#include "libaio.h" -#include <errno.h> -#include "syscall.h" - -struct timespec; - +/* io_submit + libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#define NO_SYSCALL_ERRNO +#include <sys/types.h> +#include "libaio.h" +#include <errno.h> +#include "syscall.h" + +struct timespec; + int io_queue_wait(io_context_t ctx, struct timespec *timeout) -{ - return io_getevents(ctx, 0, 0, NULL, timeout); -} +{ + return io_getevents(ctx, 0, 0, NULL, timeout); +} diff --git a/contrib/libs/libaio/io_setup.c b/contrib/libs/libaio/io_setup.c index 04806c1c3b..a3a44bb4d5 100644 --- a/contrib/libs/libaio/io_setup.c +++ b/contrib/libs/libaio/io_setup.c @@ -1,23 +1,23 @@ -/* io_setup - libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include <errno.h> -#include "libaio.h" -#include "syscall.h" - -io_syscall2(int, io_setup, io_setup, int, maxevents, io_context_t *, ctxp) +/* io_setup + libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <errno.h> +#include "libaio.h" +#include "syscall.h" + +io_syscall2(int, io_setup, io_setup, int, maxevents, io_context_t *, ctxp) diff --git a/contrib/libs/libaio/io_submit.c b/contrib/libs/libaio/io_submit.c index 21d323ab5b..3cc9590703 100644 --- a/contrib/libs/libaio/io_submit.c +++ b/contrib/libs/libaio/io_submit.c @@ -1,23 +1,23 @@ -/* io_submit - libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include <errno.h> -#include "libaio.h" -#include "syscall.h" - -io_syscall3(int, io_submit, io_submit, io_context_t, ctx, long, nr, struct iocb **, iocbs) +/* io_submit + libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <errno.h> +#include "libaio.h" +#include "syscall.h" + +io_syscall3(int, io_submit, io_submit, io_context_t, ctx, long, nr, struct iocb **, iocbs) diff --git a/contrib/libs/libaio/libaio.h b/contrib/libs/libaio/libaio.h index 39605ca3cd..4a4e0f5cba 100644 --- a/contrib/libs/libaio/libaio.h +++ b/contrib/libs/libaio/libaio.h @@ -1,271 +1,271 @@ -/* /usr/include/libaio.h - * - * Copyright 2000,2001,2002 Red Hat, Inc. - * - * Written by Benjamin LaHaise <bcrl@redhat.com> - * - * libaio Linux async I/O interface - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef __LIBAIO_H -#define __LIBAIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <sys/types.h> -#include <string.h> - -struct timespec; -struct sockaddr; -struct iovec; - -typedef struct io_context *io_context_t; - -typedef enum io_iocb_cmd { - IO_CMD_PREAD = 0, - IO_CMD_PWRITE = 1, - - IO_CMD_FSYNC = 2, - IO_CMD_FDSYNC = 3, - - IO_CMD_POLL = 5, /* Never implemented in mainline, see io_prep_poll */ - IO_CMD_NOOP = 6, - IO_CMD_PREADV = 7, - IO_CMD_PWRITEV = 8, -} io_iocb_cmd_t; - -/* little endian, 32 bits */ -#if defined(__i386__) || (defined(__arm__) && !defined(__ARMEB__)) || \ - defined(__sh__) || defined(__bfin__) || defined(__MIPSEL__) || \ - defined(__cris__) || \ - (defined(__GNUC__) && defined(__BYTE_ORDER__) && \ - __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_LONG__ == 4) -#define PADDED(x, y) x; unsigned y -#define PADDEDptr(x, y) x; unsigned y -#define PADDEDul(x, y) unsigned long x; unsigned y - -/* little endian, 64 bits */ -#elif defined(__ia64__) || defined(__x86_64__) || defined(__alpha__) || \ - (defined(__aarch64__) && defined(__AARCH64EL__)) || \ - (defined(__GNUC__) && defined(__BYTE_ORDER__) && \ - __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_LONG__ == 8) -#define PADDED(x, y) x, y -#define PADDEDptr(x, y) x -#define PADDEDul(x, y) unsigned long x - -/* big endian, 64 bits */ -#elif defined(__powerpc64__) || defined(__s390x__) || \ - (defined(__sparc__) && defined(__arch64__)) || \ - (defined(__aarch64__) && defined(__AARCH64EB__)) || \ - (defined(__GNUC__) && defined(__BYTE_ORDER__) && \ - __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_LONG__ == 8) -#define PADDED(x, y) unsigned y; x -#define PADDEDptr(x,y) x -#define PADDEDul(x, y) unsigned long x - -/* big endian, 32 bits */ -#elif defined(__PPC__) || defined(__s390__) || \ - (defined(__arm__) && defined(__ARMEB__)) || \ - defined(__sparc__) || defined(__MIPSEB__) || defined(__m68k__) || \ - defined(__hppa__) || defined(__frv__) || defined(__avr32__) || \ - (defined(__GNUC__) && defined(__BYTE_ORDER__) && \ - __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_LONG__ == 4) -#define PADDED(x, y) unsigned y; x -#define PADDEDptr(x, y) unsigned y; x -#define PADDEDul(x, y) unsigned y; unsigned long x - -#else -#error endian? -#endif - -struct io_iocb_poll { - PADDED(int events, __pad1); -}; /* result code is the set of result flags or -'ve errno */ - -struct io_iocb_sockaddr { - struct sockaddr *addr; - int len; -}; /* result code is the length of the sockaddr, or -'ve errno */ - -struct io_iocb_common { - PADDEDptr(void *buf, __pad1); - PADDEDul(nbytes, __pad2); - long long offset; - long long __pad3; - unsigned flags; - unsigned resfd; -}; /* result code is the amount read or -'ve errno */ - -struct io_iocb_vector { - const struct iovec *vec; - int nr; - long long offset; -}; /* result code is the amount read or -'ve errno */ - -struct iocb { - PADDEDptr(void *data, __pad1); /* Return in the io completion event */ - PADDED(unsigned key, __pad2); /* For use in identifying io requests */ - - short aio_lio_opcode; - short aio_reqprio; - int aio_fildes; - - union { - struct io_iocb_common c; - struct io_iocb_vector v; - struct io_iocb_poll poll; - struct io_iocb_sockaddr saddr; - } u; -}; - -struct io_event { - PADDEDptr(void *data, __pad1); - PADDEDptr(struct iocb *obj, __pad2); - PADDEDul(res, __pad3); - PADDEDul(res2, __pad4); -}; - -#undef PADDED -#undef PADDEDptr -#undef PADDEDul - -typedef void (*io_callback_t)(io_context_t ctx, struct iocb *iocb, long res, long res2); - -/* library wrappers */ -extern int io_queue_init(int maxevents, io_context_t *ctxp); -/*extern int io_queue_grow(io_context_t ctx, int new_maxevents);*/ -extern int io_queue_release(io_context_t ctx); -/*extern int io_queue_wait(io_context_t ctx, struct timespec *timeout);*/ -extern int io_queue_run(io_context_t ctx); - -/* Actual syscalls */ -extern int io_setup(int maxevents, io_context_t *ctxp); -extern int io_destroy(io_context_t ctx); -extern int io_submit(io_context_t ctx, long nr, struct iocb *ios[]); -extern int io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt); -extern int io_getevents(io_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct timespec *timeout); - - -static inline void io_set_callback(struct iocb *iocb, io_callback_t cb) -{ - iocb->data = (void *)cb; -} - -static inline void io_prep_pread(struct iocb *iocb, int fd, void *buf, size_t count, long long offset) -{ - memset(iocb, 0, sizeof(*iocb)); - iocb->aio_fildes = fd; - iocb->aio_lio_opcode = IO_CMD_PREAD; - iocb->aio_reqprio = 0; - iocb->u.c.buf = buf; - iocb->u.c.nbytes = count; - iocb->u.c.offset = offset; -} - -static inline void io_prep_pwrite(struct iocb *iocb, int fd, void *buf, size_t count, long long offset) -{ - memset(iocb, 0, sizeof(*iocb)); - iocb->aio_fildes = fd; - iocb->aio_lio_opcode = IO_CMD_PWRITE; - iocb->aio_reqprio = 0; - iocb->u.c.buf = buf; - iocb->u.c.nbytes = count; - iocb->u.c.offset = offset; -} - -static inline void io_prep_preadv(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset) -{ - memset(iocb, 0, sizeof(*iocb)); - iocb->aio_fildes = fd; - iocb->aio_lio_opcode = IO_CMD_PREADV; - iocb->aio_reqprio = 0; - iocb->u.c.buf = (void *)iov; - iocb->u.c.nbytes = iovcnt; - iocb->u.c.offset = offset; -} - -static inline void io_prep_pwritev(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset) -{ - memset(iocb, 0, sizeof(*iocb)); - iocb->aio_fildes = fd; - iocb->aio_lio_opcode = IO_CMD_PWRITEV; - iocb->aio_reqprio = 0; - iocb->u.c.buf = (void *)iov; - iocb->u.c.nbytes = iovcnt; - iocb->u.c.offset = offset; -} - -/* Jeff Moyer says this was implemented in Red Hat AS2.1 and RHEL3. - * AFAICT, it was never in mainline, and should not be used. --RR */ -static inline void io_prep_poll(struct iocb *iocb, int fd, int events) -{ - memset(iocb, 0, sizeof(*iocb)); - iocb->aio_fildes = fd; - iocb->aio_lio_opcode = IO_CMD_POLL; - iocb->aio_reqprio = 0; - iocb->u.poll.events = events; -} - -static inline int io_poll(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd, int events) -{ - io_prep_poll(iocb, fd, events); - io_set_callback(iocb, cb); - return io_submit(ctx, 1, &iocb); -} - -static inline void io_prep_fsync(struct iocb *iocb, int fd) -{ - memset(iocb, 0, sizeof(*iocb)); - iocb->aio_fildes = fd; - iocb->aio_lio_opcode = IO_CMD_FSYNC; - iocb->aio_reqprio = 0; -} - -static inline int io_fsync(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd) -{ - io_prep_fsync(iocb, fd); - io_set_callback(iocb, cb); - return io_submit(ctx, 1, &iocb); -} - -static inline void io_prep_fdsync(struct iocb *iocb, int fd) -{ - memset(iocb, 0, sizeof(*iocb)); - iocb->aio_fildes = fd; - iocb->aio_lio_opcode = IO_CMD_FDSYNC; - iocb->aio_reqprio = 0; -} - -static inline int io_fdsync(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd) -{ - io_prep_fdsync(iocb, fd); - io_set_callback(iocb, cb); - return io_submit(ctx, 1, &iocb); -} - -static inline void io_set_eventfd(struct iocb *iocb, int eventfd) -{ - iocb->u.c.flags |= (1 << 0) /* IOCB_FLAG_RESFD */; - iocb->u.c.resfd = eventfd; -} - -#ifdef __cplusplus -} -#endif - -#endif /* __LIBAIO_H */ +/* /usr/include/libaio.h + * + * Copyright 2000,2001,2002 Red Hat, Inc. + * + * Written by Benjamin LaHaise <bcrl@redhat.com> + * + * libaio Linux async I/O interface + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __LIBAIO_H +#define __LIBAIO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <sys/types.h> +#include <string.h> + +struct timespec; +struct sockaddr; +struct iovec; + +typedef struct io_context *io_context_t; + +typedef enum io_iocb_cmd { + IO_CMD_PREAD = 0, + IO_CMD_PWRITE = 1, + + IO_CMD_FSYNC = 2, + IO_CMD_FDSYNC = 3, + + IO_CMD_POLL = 5, /* Never implemented in mainline, see io_prep_poll */ + IO_CMD_NOOP = 6, + IO_CMD_PREADV = 7, + IO_CMD_PWRITEV = 8, +} io_iocb_cmd_t; + +/* little endian, 32 bits */ +#if defined(__i386__) || (defined(__arm__) && !defined(__ARMEB__)) || \ + defined(__sh__) || defined(__bfin__) || defined(__MIPSEL__) || \ + defined(__cris__) || \ + (defined(__GNUC__) && defined(__BYTE_ORDER__) && \ + __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_LONG__ == 4) +#define PADDED(x, y) x; unsigned y +#define PADDEDptr(x, y) x; unsigned y +#define PADDEDul(x, y) unsigned long x; unsigned y + +/* little endian, 64 bits */ +#elif defined(__ia64__) || defined(__x86_64__) || defined(__alpha__) || \ + (defined(__aarch64__) && defined(__AARCH64EL__)) || \ + (defined(__GNUC__) && defined(__BYTE_ORDER__) && \ + __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_LONG__ == 8) +#define PADDED(x, y) x, y +#define PADDEDptr(x, y) x +#define PADDEDul(x, y) unsigned long x + +/* big endian, 64 bits */ +#elif defined(__powerpc64__) || defined(__s390x__) || \ + (defined(__sparc__) && defined(__arch64__)) || \ + (defined(__aarch64__) && defined(__AARCH64EB__)) || \ + (defined(__GNUC__) && defined(__BYTE_ORDER__) && \ + __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_LONG__ == 8) +#define PADDED(x, y) unsigned y; x +#define PADDEDptr(x,y) x +#define PADDEDul(x, y) unsigned long x + +/* big endian, 32 bits */ +#elif defined(__PPC__) || defined(__s390__) || \ + (defined(__arm__) && defined(__ARMEB__)) || \ + defined(__sparc__) || defined(__MIPSEB__) || defined(__m68k__) || \ + defined(__hppa__) || defined(__frv__) || defined(__avr32__) || \ + (defined(__GNUC__) && defined(__BYTE_ORDER__) && \ + __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_LONG__ == 4) +#define PADDED(x, y) unsigned y; x +#define PADDEDptr(x, y) unsigned y; x +#define PADDEDul(x, y) unsigned y; unsigned long x + +#else +#error endian? +#endif + +struct io_iocb_poll { + PADDED(int events, __pad1); +}; /* result code is the set of result flags or -'ve errno */ + +struct io_iocb_sockaddr { + struct sockaddr *addr; + int len; +}; /* result code is the length of the sockaddr, or -'ve errno */ + +struct io_iocb_common { + PADDEDptr(void *buf, __pad1); + PADDEDul(nbytes, __pad2); + long long offset; + long long __pad3; + unsigned flags; + unsigned resfd; +}; /* result code is the amount read or -'ve errno */ + +struct io_iocb_vector { + const struct iovec *vec; + int nr; + long long offset; +}; /* result code is the amount read or -'ve errno */ + +struct iocb { + PADDEDptr(void *data, __pad1); /* Return in the io completion event */ + PADDED(unsigned key, __pad2); /* For use in identifying io requests */ + + short aio_lio_opcode; + short aio_reqprio; + int aio_fildes; + + union { + struct io_iocb_common c; + struct io_iocb_vector v; + struct io_iocb_poll poll; + struct io_iocb_sockaddr saddr; + } u; +}; + +struct io_event { + PADDEDptr(void *data, __pad1); + PADDEDptr(struct iocb *obj, __pad2); + PADDEDul(res, __pad3); + PADDEDul(res2, __pad4); +}; + +#undef PADDED +#undef PADDEDptr +#undef PADDEDul + +typedef void (*io_callback_t)(io_context_t ctx, struct iocb *iocb, long res, long res2); + +/* library wrappers */ +extern int io_queue_init(int maxevents, io_context_t *ctxp); +/*extern int io_queue_grow(io_context_t ctx, int new_maxevents);*/ +extern int io_queue_release(io_context_t ctx); +/*extern int io_queue_wait(io_context_t ctx, struct timespec *timeout);*/ +extern int io_queue_run(io_context_t ctx); + +/* Actual syscalls */ +extern int io_setup(int maxevents, io_context_t *ctxp); +extern int io_destroy(io_context_t ctx); +extern int io_submit(io_context_t ctx, long nr, struct iocb *ios[]); +extern int io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt); +extern int io_getevents(io_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct timespec *timeout); + + +static inline void io_set_callback(struct iocb *iocb, io_callback_t cb) +{ + iocb->data = (void *)cb; +} + +static inline void io_prep_pread(struct iocb *iocb, int fd, void *buf, size_t count, long long offset) +{ + memset(iocb, 0, sizeof(*iocb)); + iocb->aio_fildes = fd; + iocb->aio_lio_opcode = IO_CMD_PREAD; + iocb->aio_reqprio = 0; + iocb->u.c.buf = buf; + iocb->u.c.nbytes = count; + iocb->u.c.offset = offset; +} + +static inline void io_prep_pwrite(struct iocb *iocb, int fd, void *buf, size_t count, long long offset) +{ + memset(iocb, 0, sizeof(*iocb)); + iocb->aio_fildes = fd; + iocb->aio_lio_opcode = IO_CMD_PWRITE; + iocb->aio_reqprio = 0; + iocb->u.c.buf = buf; + iocb->u.c.nbytes = count; + iocb->u.c.offset = offset; +} + +static inline void io_prep_preadv(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset) +{ + memset(iocb, 0, sizeof(*iocb)); + iocb->aio_fildes = fd; + iocb->aio_lio_opcode = IO_CMD_PREADV; + iocb->aio_reqprio = 0; + iocb->u.c.buf = (void *)iov; + iocb->u.c.nbytes = iovcnt; + iocb->u.c.offset = offset; +} + +static inline void io_prep_pwritev(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset) +{ + memset(iocb, 0, sizeof(*iocb)); + iocb->aio_fildes = fd; + iocb->aio_lio_opcode = IO_CMD_PWRITEV; + iocb->aio_reqprio = 0; + iocb->u.c.buf = (void *)iov; + iocb->u.c.nbytes = iovcnt; + iocb->u.c.offset = offset; +} + +/* Jeff Moyer says this was implemented in Red Hat AS2.1 and RHEL3. + * AFAICT, it was never in mainline, and should not be used. --RR */ +static inline void io_prep_poll(struct iocb *iocb, int fd, int events) +{ + memset(iocb, 0, sizeof(*iocb)); + iocb->aio_fildes = fd; + iocb->aio_lio_opcode = IO_CMD_POLL; + iocb->aio_reqprio = 0; + iocb->u.poll.events = events; +} + +static inline int io_poll(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd, int events) +{ + io_prep_poll(iocb, fd, events); + io_set_callback(iocb, cb); + return io_submit(ctx, 1, &iocb); +} + +static inline void io_prep_fsync(struct iocb *iocb, int fd) +{ + memset(iocb, 0, sizeof(*iocb)); + iocb->aio_fildes = fd; + iocb->aio_lio_opcode = IO_CMD_FSYNC; + iocb->aio_reqprio = 0; +} + +static inline int io_fsync(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd) +{ + io_prep_fsync(iocb, fd); + io_set_callback(iocb, cb); + return io_submit(ctx, 1, &iocb); +} + +static inline void io_prep_fdsync(struct iocb *iocb, int fd) +{ + memset(iocb, 0, sizeof(*iocb)); + iocb->aio_fildes = fd; + iocb->aio_lio_opcode = IO_CMD_FDSYNC; + iocb->aio_reqprio = 0; +} + +static inline int io_fdsync(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd) +{ + io_prep_fdsync(iocb, fd); + io_set_callback(iocb, cb); + return io_submit(ctx, 1, &iocb); +} + +static inline void io_set_eventfd(struct iocb *iocb, int eventfd) +{ + iocb->u.c.flags |= (1 << 0) /* IOCB_FLAG_RESFD */; + iocb->u.c.resfd = eventfd; +} + +#ifdef __cplusplus +} +#endif + +#endif /* __LIBAIO_H */ diff --git a/contrib/libs/libaio/raw_syscall.c b/contrib/libs/libaio/raw_syscall.c index 08688ba15b..c3fe4b8deb 100644 --- a/contrib/libs/libaio/raw_syscall.c +++ b/contrib/libs/libaio/raw_syscall.c @@ -1,19 +1,19 @@ -#include "syscall.h" - -#if defined(__ia64__) -/* based on code from glibc by Jes Sorensen */ -__asm__(".text\n" - ".globl __ia64_aio_raw_syscall\n" - ".proc __ia64_aio_raw_syscall\n" - "__ia64_aio_raw_syscall:\n" - "alloc r2=ar.pfs,1,0,8,0\n" - "mov r15=r32\n" - "break 0x100000\n" - ";;" - "br.ret.sptk.few b0\n" - ".size __ia64_aio_raw_syscall, . - __ia64_aio_raw_syscall\n" - ".endp __ia64_aio_raw_syscall" -); -#endif - -; +#include "syscall.h" + +#if defined(__ia64__) +/* based on code from glibc by Jes Sorensen */ +__asm__(".text\n" + ".globl __ia64_aio_raw_syscall\n" + ".proc __ia64_aio_raw_syscall\n" + "__ia64_aio_raw_syscall:\n" + "alloc r2=ar.pfs,1,0,8,0\n" + "mov r15=r32\n" + "break 0x100000\n" + ";;" + "br.ret.sptk.few b0\n" + ".size __ia64_aio_raw_syscall, . - __ia64_aio_raw_syscall\n" + ".endp __ia64_aio_raw_syscall" +); +#endif + +; diff --git a/contrib/libs/libaio/static/ya.make b/contrib/libs/libaio/static/ya.make index d7d509dba9..c4a7e200bb 100644 --- a/contrib/libs/libaio/static/ya.make +++ b/contrib/libs/libaio/static/ya.make @@ -1,6 +1,6 @@ -# sources downloaded from: https://git.fedorahosted.org/cgit/libaio.git -LIBRARY() - +# sources downloaded from: https://git.fedorahosted.org/cgit/libaio.git +LIBRARY() + IF (ARCH_ARMV7 OR ARCH_ARM64) LICENSE( GPL-2.0-only AND @@ -21,11 +21,11 @@ OWNER( g:contrib g:cpp-contrib ) - -NO_UTIL() -NO_RUNTIME() - +NO_UTIL() + +NO_RUNTIME() + PROVIDES(libaio) SRCDIR(contrib/libs/libaio) @@ -34,17 +34,17 @@ ADDINCL( contrib/libs/libaio ) -SRCS( - io_cancel.c - io_destroy.c - io_getevents.c - io_queue_init.c - io_queue_release.c - io_queue_run.c - io_queue_wait.c - io_setup.c - io_submit.c - raw_syscall.c -) - -END() +SRCS( + io_cancel.c + io_destroy.c + io_getevents.c + io_queue_init.c + io_queue_release.c + io_queue_run.c + io_queue_wait.c + io_setup.c + io_submit.c + raw_syscall.c +) + +END() diff --git a/contrib/libs/libaio/syscall-alpha.h b/contrib/libs/libaio/syscall-alpha.h index 2e3bc67a5e..467b74f07e 100644 --- a/contrib/libs/libaio/syscall-alpha.h +++ b/contrib/libs/libaio/syscall-alpha.h @@ -1,145 +1,145 @@ -#define __NR_io_setup 398 -#define __NR_io_destroy 399 -#define __NR_io_getevents 400 -#define __NR_io_submit 401 -#define __NR_io_cancel 402 - -#define inline_syscall_r0_asm -#define inline_syscall_r0_out_constraint "=v" - -#define inline_syscall_clobbers \ - "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \ - "$22", "$23", "$24", "$25", "$27", "$28", "memory" - -#define inline_syscall0(name, args...) \ -{ \ +#define __NR_io_setup 398 +#define __NR_io_destroy 399 +#define __NR_io_getevents 400 +#define __NR_io_submit 401 +#define __NR_io_cancel 402 + +#define inline_syscall_r0_asm +#define inline_syscall_r0_out_constraint "=v" + +#define inline_syscall_clobbers \ + "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \ + "$22", "$23", "$24", "$25", "$27", "$28", "memory" + +#define inline_syscall0(name, args...) \ +{ \ register long _sc_0 inline_syscall_r0_asm; \ register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19) \ - : "0"(_sc_0) \ - : inline_syscall_clobbers, \ - "$16", "$17", "$18", "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall1(name,arg1) \ -{ \ + \ + _sc_0 = name; \ + __asm__ __volatile__ \ + ("callsys # %0 %1 <= %2" \ + : inline_syscall_r0_out_constraint (_sc_0), \ + "=r"(_sc_19) \ + : "0"(_sc_0) \ + : inline_syscall_clobbers, \ + "$16", "$17", "$18", "$20", "$21"); \ + _sc_ret = _sc_0, _sc_err = _sc_19; \ +} + +#define inline_syscall1(name,arg1) \ +{ \ register long _sc_0 inline_syscall_r0_asm; \ register long _sc_16 __asm__("$16"); \ register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16) \ - : "0"(_sc_0), "2"(_sc_16) \ - : inline_syscall_clobbers, \ - "$17", "$18", "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall2(name,arg1,arg2) \ -{ \ + \ + _sc_0 = name; \ + _sc_16 = (long) (arg1); \ + __asm__ __volatile__ \ + ("callsys # %0 %1 <= %2 %3" \ + : inline_syscall_r0_out_constraint (_sc_0), \ + "=r"(_sc_19), "=r"(_sc_16) \ + : "0"(_sc_0), "2"(_sc_16) \ + : inline_syscall_clobbers, \ + "$17", "$18", "$20", "$21"); \ + _sc_ret = _sc_0, _sc_err = _sc_19; \ +} + +#define inline_syscall2(name,arg1,arg2) \ +{ \ register long _sc_0 inline_syscall_r0_asm; \ register long _sc_16 __asm__("$16"); \ register long _sc_17 __asm__("$17"); \ register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17) \ - : inline_syscall_clobbers, \ - "$18", "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall3(name,arg1,arg2,arg3) \ -{ \ + \ + _sc_0 = name; \ + _sc_16 = (long) (arg1); \ + _sc_17 = (long) (arg2); \ + __asm__ __volatile__ \ + ("callsys # %0 %1 <= %2 %3 %4" \ + : inline_syscall_r0_out_constraint (_sc_0), \ + "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17) \ + : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17) \ + : inline_syscall_clobbers, \ + "$18", "$20", "$21"); \ + _sc_ret = _sc_0, _sc_err = _sc_19; \ +} + +#define inline_syscall3(name,arg1,arg2,arg3) \ +{ \ register long _sc_0 inline_syscall_r0_asm; \ register long _sc_16 __asm__("$16"); \ register long _sc_17 __asm__("$17"); \ register long _sc_18 __asm__("$18"); \ register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - _sc_18 = (long) (arg3); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4 %5" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ - "=r"(_sc_18) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \ - "4"(_sc_18) \ - : inline_syscall_clobbers, "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall4(name,arg1,arg2,arg3,arg4) \ -{ \ + \ + _sc_0 = name; \ + _sc_16 = (long) (arg1); \ + _sc_17 = (long) (arg2); \ + _sc_18 = (long) (arg3); \ + __asm__ __volatile__ \ + ("callsys # %0 %1 <= %2 %3 %4 %5" \ + : inline_syscall_r0_out_constraint (_sc_0), \ + "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ + "=r"(_sc_18) \ + : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \ + "4"(_sc_18) \ + : inline_syscall_clobbers, "$20", "$21"); \ + _sc_ret = _sc_0, _sc_err = _sc_19; \ +} + +#define inline_syscall4(name,arg1,arg2,arg3,arg4) \ +{ \ register long _sc_0 inline_syscall_r0_asm; \ register long _sc_16 __asm__("$16"); \ register long _sc_17 __asm__("$17"); \ register long _sc_18 __asm__("$18"); \ register long _sc_19 __asm__("$19"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - _sc_18 = (long) (arg3); \ - _sc_19 = (long) (arg4); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4 %5 %6" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ - "=r"(_sc_18) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \ - "4"(_sc_18), "1"(_sc_19) \ - : inline_syscall_clobbers, "$20", "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \ -{ \ + \ + _sc_0 = name; \ + _sc_16 = (long) (arg1); \ + _sc_17 = (long) (arg2); \ + _sc_18 = (long) (arg3); \ + _sc_19 = (long) (arg4); \ + __asm__ __volatile__ \ + ("callsys # %0 %1 <= %2 %3 %4 %5 %6" \ + : inline_syscall_r0_out_constraint (_sc_0), \ + "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ + "=r"(_sc_18) \ + : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \ + "4"(_sc_18), "1"(_sc_19) \ + : inline_syscall_clobbers, "$20", "$21"); \ + _sc_ret = _sc_0, _sc_err = _sc_19; \ +} + +#define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \ +{ \ register long _sc_0 inline_syscall_r0_asm; \ register long _sc_16 __asm__("$16"); \ register long _sc_17 __asm__("$17"); \ register long _sc_18 __asm__("$18"); \ register long _sc_19 __asm__("$19"); \ register long _sc_20 __asm__("$20"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - _sc_18 = (long) (arg3); \ - _sc_19 = (long) (arg4); \ - _sc_20 = (long) (arg5); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ - "=r"(_sc_18), "=r"(_sc_20) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \ - "4"(_sc_18), "1"(_sc_19), "5"(_sc_20) \ - : inline_syscall_clobbers, "$21"); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \ -{ \ + \ + _sc_0 = name; \ + _sc_16 = (long) (arg1); \ + _sc_17 = (long) (arg2); \ + _sc_18 = (long) (arg3); \ + _sc_19 = (long) (arg4); \ + _sc_20 = (long) (arg5); \ + __asm__ __volatile__ \ + ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7" \ + : inline_syscall_r0_out_constraint (_sc_0), \ + "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ + "=r"(_sc_18), "=r"(_sc_20) \ + : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \ + "4"(_sc_18), "1"(_sc_19), "5"(_sc_20) \ + : inline_syscall_clobbers, "$21"); \ + _sc_ret = _sc_0, _sc_err = _sc_19; \ +} + +#define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \ +{ \ register long _sc_0 inline_syscall_r0_asm; \ register long _sc_16 __asm__("$16"); \ register long _sc_17 __asm__("$17"); \ @@ -147,63 +147,63 @@ register long _sc_19 __asm__("$19"); \ register long _sc_20 __asm__("$20"); \ register long _sc_21 __asm__("$21"); \ - \ - _sc_0 = name; \ - _sc_16 = (long) (arg1); \ - _sc_17 = (long) (arg2); \ - _sc_18 = (long) (arg3); \ - _sc_19 = (long) (arg4); \ - _sc_20 = (long) (arg5); \ - _sc_21 = (long) (arg6); \ - __asm__ __volatile__ \ - ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7 %8" \ - : inline_syscall_r0_out_constraint (_sc_0), \ - "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ - "=r"(_sc_18), "=r"(_sc_20), "=r"(_sc_21) \ - : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), "4"(_sc_18), \ - "1"(_sc_19), "5"(_sc_20), "6"(_sc_21) \ - : inline_syscall_clobbers); \ - _sc_ret = _sc_0, _sc_err = _sc_19; \ -} - -#define INLINE_SYSCALL1(name, nr, args...) \ -({ \ - long _sc_ret, _sc_err; \ - inline_syscall##nr(__NR_##name, args); \ - if (_sc_err != 0) \ - { \ - _sc_ret = -(_sc_ret); \ - } \ - _sc_ret; \ -}) - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 1, arg1); \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 2, arg1, arg2); \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 3, arg1, arg2, arg3); \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 4, arg1, arg2, arg3, arg4); \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ - return (type)INLINE_SYSCALL1(sname, 5, arg1, arg2, arg3, arg4, arg5);\ -} + \ + _sc_0 = name; \ + _sc_16 = (long) (arg1); \ + _sc_17 = (long) (arg2); \ + _sc_18 = (long) (arg3); \ + _sc_19 = (long) (arg4); \ + _sc_20 = (long) (arg5); \ + _sc_21 = (long) (arg6); \ + __asm__ __volatile__ \ + ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7 %8" \ + : inline_syscall_r0_out_constraint (_sc_0), \ + "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \ + "=r"(_sc_18), "=r"(_sc_20), "=r"(_sc_21) \ + : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), "4"(_sc_18), \ + "1"(_sc_19), "5"(_sc_20), "6"(_sc_21) \ + : inline_syscall_clobbers); \ + _sc_ret = _sc_0, _sc_err = _sc_19; \ +} + +#define INLINE_SYSCALL1(name, nr, args...) \ +({ \ + long _sc_ret, _sc_err; \ + inline_syscall##nr(__NR_##name, args); \ + if (_sc_err != 0) \ + { \ + _sc_ret = -(_sc_ret); \ + } \ + _sc_ret; \ +}) + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) \ +{ \ + return (type)INLINE_SYSCALL1(sname, 1, arg1); \ +} + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1,type2 arg2) \ +{ \ + return (type)INLINE_SYSCALL1(sname, 2, arg1, arg2); \ +} + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ +type fname(type1 arg1,type2 arg2,type3 arg3) \ +{ \ + return (type)INLINE_SYSCALL1(sname, 3, arg1, arg2, arg3); \ +} + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ +type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +{ \ + return (type)INLINE_SYSCALL1(sname, 4, arg1, arg2, arg3, arg4); \ +} + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ +type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ +{ \ + return (type)INLINE_SYSCALL1(sname, 5, arg1, arg2, arg3, arg4, arg5);\ +} diff --git a/contrib/libs/libaio/syscall-arm.h b/contrib/libs/libaio/syscall-arm.h index d703c0beea..4a9b665969 100644 --- a/contrib/libs/libaio/syscall-arm.h +++ b/contrib/libs/libaio/syscall-arm.h @@ -1,116 +1,116 @@ -/* - * linux/include/asm-arm/unistd.h - * - * Copyright (C) 2001-2005 Russell King - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Please forward _all_ changes to this file to rmk@arm.linux.org.uk, - * no matter what the change is. Thanks! - */ - -#define __NR_OABI_SYSCALL_BASE 0x900000 - -#if defined(__thumb__) || defined(__ARM_EABI__) -#define __NR_SYSCALL_BASE 0 -#else -#define __NR_SYSCALL_BASE __NR_OABI_SYSCALL_BASE -#endif - -#define __NR_io_setup (__NR_SYSCALL_BASE+243) -#define __NR_io_destroy (__NR_SYSCALL_BASE+244) -#define __NR_io_getevents (__NR_SYSCALL_BASE+245) -#define __NR_io_submit (__NR_SYSCALL_BASE+246) -#define __NR_io_cancel (__NR_SYSCALL_BASE+247) - -#define __sys2(x) #x -#define __sys1(x) __sys2(x) - -#if defined(__thumb__) || defined(__ARM_EABI__) -#define __SYS_REG(name) register long __sysreg __asm__("r7") = __NR_##name; -#define __SYS_REG_LIST(regs...) "r" (__sysreg) , ##regs -#define __syscall(name) "swi\t0" -#else -#define __SYS_REG(name) -#define __SYS_REG_LIST(regs...) regs -#define __syscall(name) "swi\t" __sys1(__NR_##name) "" -#endif - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) { \ - __SYS_REG(sname) \ +/* + * linux/include/asm-arm/unistd.h + * + * Copyright (C) 2001-2005 Russell King + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Please forward _all_ changes to this file to rmk@arm.linux.org.uk, + * no matter what the change is. Thanks! + */ + +#define __NR_OABI_SYSCALL_BASE 0x900000 + +#if defined(__thumb__) || defined(__ARM_EABI__) +#define __NR_SYSCALL_BASE 0 +#else +#define __NR_SYSCALL_BASE __NR_OABI_SYSCALL_BASE +#endif + +#define __NR_io_setup (__NR_SYSCALL_BASE+243) +#define __NR_io_destroy (__NR_SYSCALL_BASE+244) +#define __NR_io_getevents (__NR_SYSCALL_BASE+245) +#define __NR_io_submit (__NR_SYSCALL_BASE+246) +#define __NR_io_cancel (__NR_SYSCALL_BASE+247) + +#define __sys2(x) #x +#define __sys1(x) __sys2(x) + +#if defined(__thumb__) || defined(__ARM_EABI__) +#define __SYS_REG(name) register long __sysreg __asm__("r7") = __NR_##name; +#define __SYS_REG_LIST(regs...) "r" (__sysreg) , ##regs +#define __syscall(name) "swi\t0" +#else +#define __SYS_REG(name) +#define __SYS_REG_LIST(regs...) regs +#define __syscall(name) "swi\t" __sys1(__NR_##name) "" +#endif + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) { \ + __SYS_REG(sname) \ register long __r0 __asm__("r0") = (long)arg1; \ register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) { \ - __SYS_REG(sname) \ + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_r0) \ + : __SYS_REG_LIST( "0" (__r0) ) \ + : "memory" ); \ + return (type) __res_r0; \ +} + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1,type2 arg2) { \ + __SYS_REG(sname) \ register long __r0 __asm__("r0") = (long)arg1; \ register long __r1 __asm__("r1") = (long)arg2; \ register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0), "r" (__r1) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) { \ - __SYS_REG(sname) \ + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_r0) \ + : __SYS_REG_LIST( "0" (__r0), "r" (__r1) ) \ + : "memory" ); \ + return (type) __res_r0; \ +} + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ +type fname(type1 arg1,type2 arg2,type3 arg3) { \ + __SYS_REG(sname) \ register long __r0 __asm__("r0") = (long)arg1; \ register long __r1 __asm__("r1") = (long)arg2; \ register long __r2 __asm__("r2") = (long)arg3; \ register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ - __SYS_REG(sname) \ + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_r0) \ + : __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2) ) \ + : "memory" ); \ + return (type) __res_r0; \ +} + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\ +type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + __SYS_REG(sname) \ register long __r0 __asm__("r0") = (long)arg1; \ register long __r1 __asm__("r1") = (long)arg2; \ register long __r2 __asm__("r2") = (long)arg3; \ register long __r3 __asm__("r3") = (long)arg4; \ register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) {\ - __SYS_REG(sname) \ + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_r0) \ + : __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) ) \ + : "memory" ); \ + return (type) __res_r0; \ +} + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ +type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) {\ + __SYS_REG(sname) \ register long __r0 __asm__("r0") = (long)arg1; \ register long __r1 __asm__("r1") = (long)arg2; \ register long __r2 __asm__("r2") = (long)arg3; \ register long __r3 __asm__("r3") = (long)arg4; \ register long __r4 __asm__("r4") = (long)arg5; \ register long __res_r0 __asm__("r0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_r0) \ - : __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2), \ - "r" (__r3), "r" (__r4) ) \ - : "memory" ); \ - return (type) __res_r0; \ -} - + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_r0) \ + : __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2), \ + "r" (__r3), "r" (__r4) ) \ + : "memory" ); \ + return (type) __res_r0; \ +} + diff --git a/contrib/libs/libaio/syscall-arm64.h b/contrib/libs/libaio/syscall-arm64.h index fb2c5e024e..031c571824 100644 --- a/contrib/libs/libaio/syscall-arm64.h +++ b/contrib/libs/libaio/syscall-arm64.h @@ -1,101 +1,101 @@ -/* - * linux/include/asm-arm/unistd.h - * - * Copyright (C) 2001-2005 Russell King - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Please forward _all_ changes to this file to rmk@arm.linux.org.uk, - * no matter what the change is. Thanks! - */ - -#define __NR_io_setup 0 -#define __NR_io_destroy 1 -#define __NR_io_submit 2 -#define __NR_io_cancel 3 -#define __NR_io_getevents 4 - -#define __sys2(x) #x -#define __sys1(x) __sys2(x) - -#define __SYS_REG(name) register long __sysreg __asm__("w8") = __NR_##name; -#define __SYS_REG_LIST(regs...) "r" (__sysreg) , ##regs -#define __syscall(name) "svc\t#0" - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) { \ - __SYS_REG(sname) \ +/* + * linux/include/asm-arm/unistd.h + * + * Copyright (C) 2001-2005 Russell King + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Please forward _all_ changes to this file to rmk@arm.linux.org.uk, + * no matter what the change is. Thanks! + */ + +#define __NR_io_setup 0 +#define __NR_io_destroy 1 +#define __NR_io_submit 2 +#define __NR_io_cancel 3 +#define __NR_io_getevents 4 + +#define __sys2(x) #x +#define __sys1(x) __sys2(x) + +#define __SYS_REG(name) register long __sysreg __asm__("w8") = __NR_##name; +#define __SYS_REG_LIST(regs...) "r" (__sysreg) , ##regs +#define __syscall(name) "svc\t#0" + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) { \ + __SYS_REG(sname) \ register long __x0 __asm__("x0") = (long)arg1; \ register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) { \ - __SYS_REG(sname) \ + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_x0) \ + : __SYS_REG_LIST( "0" (__x0) ) \ + : "memory" ); \ + return (type) __res_x0; \ +} + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1,type2 arg2) { \ + __SYS_REG(sname) \ register long __x0 __asm__("x0") = (long)arg1; \ register long __x1 __asm__("x1") = (long)arg2; \ register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0), "r" (__x1) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) { \ - __SYS_REG(sname) \ + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_x0) \ + : __SYS_REG_LIST( "0" (__x0), "r" (__x1) ) \ + : "memory" ); \ + return (type) __res_x0; \ +} + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ +type fname(type1 arg1,type2 arg2,type3 arg3) { \ + __SYS_REG(sname) \ register long __x0 __asm__("x0") = (long)arg1; \ register long __x1 __asm__("x1") = (long)arg2; \ register long __x2 __asm__("x2") = (long)arg3; \ register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0), "r" (__x1), "r" (__x2) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ - __SYS_REG(sname) \ + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_x0) \ + : __SYS_REG_LIST( "0" (__x0), "r" (__x1), "r" (__x2) ) \ + : "memory" ); \ + return (type) __res_x0; \ +} + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\ +type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + __SYS_REG(sname) \ register long __x0 __asm__("x0") = (long)arg1; \ register long __x1 __asm__("x1") = (long)arg2; \ register long __x2 __asm__("x2") = (long)arg3; \ register long __x3 __asm__("x3") = (long)arg4; \ register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0), "r" (__x1), "r" (__x2), "r" (__x3) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) {\ - __SYS_REG(sname) \ + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_x0) \ + : __SYS_REG_LIST( "0" (__x0), "r" (__x1), "r" (__x2), "r" (__x3) ) \ + : "memory" ); \ + return (type) __res_x0; \ +} + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ +type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) {\ + __SYS_REG(sname) \ register long __x0 __asm__("x0") = (long)arg1; \ register long __x1 __asm__("x1") = (long)arg2; \ register long __x2 __asm__("x2") = (long)arg3; \ register long __x3 __asm__("x3") = (long)arg4; \ register long __x4 __asm__("x4") = (long)arg5; \ register long __res_x0 __asm__("x0"); \ - __asm__ __volatile__ ( \ - __syscall(sname) \ - : "=r" (__res_x0) \ - : __SYS_REG_LIST( "0" (__x0), "r" (__x1), "r" (__x2), \ - "r" (__x3), "r" (__x4) ) \ - : "memory" ); \ - return (type) __res_x0; \ -} + __asm__ __volatile__ ( \ + __syscall(sname) \ + : "=r" (__res_x0) \ + : __SYS_REG_LIST( "0" (__x0), "r" (__x1), "r" (__x2), \ + "r" (__x3), "r" (__x4) ) \ + : "memory" ); \ + return (type) __res_x0; \ +} diff --git a/contrib/libs/libaio/syscall-generic.h b/contrib/libs/libaio/syscall-generic.h index 24b3a3dec1..24d7c7c816 100644 --- a/contrib/libs/libaio/syscall-generic.h +++ b/contrib/libs/libaio/syscall-generic.h @@ -1,29 +1,29 @@ -#include <errno.h> -#include <unistd.h> -#include <sys/syscall.h> - -#define _body_io_syscall(sname, args...) \ -{ \ - int ret = syscall(__NR_##sname, ## args); \ - return ret < 0 ? -errno : ret; \ -} - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -_body_io_syscall(sname, (long)arg1) - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -_body_io_syscall(sname, (long)arg1, (long)arg2) - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3) - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4) - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4, (long)arg5) +#include <errno.h> +#include <unistd.h> +#include <sys/syscall.h> + +#define _body_io_syscall(sname, args...) \ +{ \ + int ret = syscall(__NR_##sname, ## args); \ + return ret < 0 ? -errno : ret; \ +} + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) \ +_body_io_syscall(sname, (long)arg1) + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1,type2 arg2) \ +_body_io_syscall(sname, (long)arg1, (long)arg2) + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ +type fname(type1 arg1,type2 arg2,type3 arg3) \ +_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3) + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ +type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4) + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, type5,arg5) \ +type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ +_body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4, (long)arg5) diff --git a/contrib/libs/libaio/syscall-i386.h b/contrib/libs/libaio/syscall-i386.h index 568dd2aaff..9576975a19 100644 --- a/contrib/libs/libaio/syscall-i386.h +++ b/contrib/libs/libaio/syscall-i386.h @@ -1,72 +1,72 @@ -#define __NR_io_setup 245 -#define __NR_io_destroy 246 -#define __NR_io_getevents 247 -#define __NR_io_submit 248 -#define __NR_io_cancel 249 - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ -long __res; \ -__asm__ volatile ("xchgl %%edi,%%ebx\n" \ - "int $0x80\n" \ - "xchgl %%edi,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1))); \ -return __res; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -__asm__ volatile ("xchgl %%edi,%%ebx\n" \ - "int $0x80\n" \ - "xchgl %%edi,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"c" ((long)(arg2))); \ -return __res; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -__asm__ volatile ("xchgl %%edi,%%ebx\n" \ - "int $0x80\n" \ - "xchgl %%edi,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3))); \ -return __res; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -__asm__ volatile ("xchgl %%edi,%%ebx\n" \ - "int $0x80\n" \ - "xchgl %%edi,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4))); \ -return __res; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -long tmp; \ -__asm__ volatile ("movl %%ebx,%7\n" \ - "movl %2,%%ebx\n" \ - "int $0x80\n" \ - "movl %7,%%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##sname),"rm" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \ - "m" (tmp)); \ -return __res; \ +#define __NR_io_setup 245 +#define __NR_io_destroy 246 +#define __NR_io_getevents 247 +#define __NR_io_submit 248 +#define __NR_io_cancel 249 + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) \ +{ \ +long __res; \ +__asm__ volatile ("xchgl %%edi,%%ebx\n" \ + "int $0x80\n" \ + "xchgl %%edi,%%ebx" \ + : "=a" (__res) \ + : "0" (__NR_##sname),"D" ((long)(arg1))); \ +return __res; \ +} + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1,type2 arg2) \ +{ \ +long __res; \ +__asm__ volatile ("xchgl %%edi,%%ebx\n" \ + "int $0x80\n" \ + "xchgl %%edi,%%ebx" \ + : "=a" (__res) \ + : "0" (__NR_##sname),"D" ((long)(arg1)),"c" ((long)(arg2))); \ +return __res; \ +} + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ +type fname(type1 arg1,type2 arg2,type3 arg3) \ +{ \ +long __res; \ +__asm__ volatile ("xchgl %%edi,%%ebx\n" \ + "int $0x80\n" \ + "xchgl %%edi,%%ebx" \ + : "=a" (__res) \ + : "0" (__NR_##sname),"D" ((long)(arg1)),"c" ((long)(arg2)), \ + "d" ((long)(arg3))); \ +return __res; \ +} + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ +type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +{ \ +long __res; \ +__asm__ volatile ("xchgl %%edi,%%ebx\n" \ + "int $0x80\n" \ + "xchgl %%edi,%%ebx" \ + : "=a" (__res) \ + : "0" (__NR_##sname),"D" ((long)(arg1)),"c" ((long)(arg2)), \ + "d" ((long)(arg3)),"S" ((long)(arg4))); \ +return __res; \ } + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ +type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ +{ \ +long __res; \ +long tmp; \ +__asm__ volatile ("movl %%ebx,%7\n" \ + "movl %2,%%ebx\n" \ + "int $0x80\n" \ + "movl %7,%%ebx" \ + : "=a" (__res) \ + : "0" (__NR_##sname),"rm" ((long)(arg1)),"c" ((long)(arg2)), \ + "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \ + "m" (tmp)); \ +return __res; \ +} diff --git a/contrib/libs/libaio/syscall-ia64.h b/contrib/libs/libaio/syscall-ia64.h index bb6a330a01..52ce9dd7d6 100644 --- a/contrib/libs/libaio/syscall-ia64.h +++ b/contrib/libs/libaio/syscall-ia64.h @@ -1,45 +1,45 @@ -#define __NR_io_setup 1238 -#define __NR_io_destroy 1239 -#define __NR_io_getevents 1240 -#define __NR_io_submit 1241 -#define __NR_io_cancel 1242 - -#define __ia64_raw_syscall(fname, sname) \ - __asm__ (".text\n" \ - ".globl " SYMSTR(fname) "\n" \ - ".proc " SYMSTR(fname) "\n" \ - SYMSTR(fname) ":\n" \ - " mov r15=" SYMSTR( __NR_ ## sname ) "\n" \ - " break 0x100000\n" \ - " ;;\n" \ - " cmp.eq p6,p0=-1,r10\n" \ - " ;;\n" \ - " (p6) sub r8=0,r8\n" \ - " br.ret.sptk.few b0\n" \ - ".size " SYMSTR(fname) ", . - " SYMSTR(fname) "\n" \ - ".endp " SYMSTR(fname) "\n" \ - ); - -#define io_syscall0(type, name) \ - extern type name(void); \ - __ia64_raw_syscall(name); - -#define io_syscall1(type, fname, sname, type1, arg1) \ - extern type fname(type1 arg1); \ - __ia64_raw_syscall(fname, sname); - -#define io_syscall2(type, fname, sname, type1, arg1, type2, arg2) \ - extern type fname(type1 arg1, type2 arg2); \ - __ia64_raw_syscall(fname, sname); - -#define io_syscall3(type, fname, sname, type1, arg1, type2, arg2, type3, arg3) \ - extern type fname(type1 arg1, type2 arg2, type3 arg3); \ - __ia64_raw_syscall(fname, sname); - -#define io_syscall4(type, fname, sname, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \ - extern type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4); \ - __ia64_raw_syscall(fname, sname); - -#define io_syscall5(type, fname, sname, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \ - extern type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5); \ - __ia64_raw_syscall(fname, sname); +#define __NR_io_setup 1238 +#define __NR_io_destroy 1239 +#define __NR_io_getevents 1240 +#define __NR_io_submit 1241 +#define __NR_io_cancel 1242 + +#define __ia64_raw_syscall(fname, sname) \ + __asm__ (".text\n" \ + ".globl " SYMSTR(fname) "\n" \ + ".proc " SYMSTR(fname) "\n" \ + SYMSTR(fname) ":\n" \ + " mov r15=" SYMSTR( __NR_ ## sname ) "\n" \ + " break 0x100000\n" \ + " ;;\n" \ + " cmp.eq p6,p0=-1,r10\n" \ + " ;;\n" \ + " (p6) sub r8=0,r8\n" \ + " br.ret.sptk.few b0\n" \ + ".size " SYMSTR(fname) ", . - " SYMSTR(fname) "\n" \ + ".endp " SYMSTR(fname) "\n" \ + ); + +#define io_syscall0(type, name) \ + extern type name(void); \ + __ia64_raw_syscall(name); + +#define io_syscall1(type, fname, sname, type1, arg1) \ + extern type fname(type1 arg1); \ + __ia64_raw_syscall(fname, sname); + +#define io_syscall2(type, fname, sname, type1, arg1, type2, arg2) \ + extern type fname(type1 arg1, type2 arg2); \ + __ia64_raw_syscall(fname, sname); + +#define io_syscall3(type, fname, sname, type1, arg1, type2, arg2, type3, arg3) \ + extern type fname(type1 arg1, type2 arg2, type3 arg3); \ + __ia64_raw_syscall(fname, sname); + +#define io_syscall4(type, fname, sname, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \ + extern type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4); \ + __ia64_raw_syscall(fname, sname); + +#define io_syscall5(type, fname, sname, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \ + extern type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5); \ + __ia64_raw_syscall(fname, sname); diff --git a/contrib/libs/libaio/syscall-ppc.h b/contrib/libs/libaio/syscall-ppc.h index 149348614c..ca70dd2092 100644 --- a/contrib/libs/libaio/syscall-ppc.h +++ b/contrib/libs/libaio/syscall-ppc.h @@ -1,94 +1,94 @@ -#define __NR_io_setup 227 -#define __NR_io_destroy 228 -#define __NR_io_getevents 229 -#define __NR_io_submit 230 -#define __NR_io_cancel 231 - -/* On powerpc a system call basically clobbers the same registers like a - * function call, with the exception of LR (which is needed for the - * "sc; bnslr" sequence) and CR (where only CR0.SO is clobbered to signal - * an error return status). - */ - -#define __syscall_nr(nr, type, name, args...) \ - unsigned long __sc_ret, __sc_err; \ - { \ - register unsigned long __sc_0 __asm__ ("r0"); \ - register unsigned long __sc_3 __asm__ ("r3"); \ - register unsigned long __sc_4 __asm__ ("r4"); \ - register unsigned long __sc_5 __asm__ ("r5"); \ - register unsigned long __sc_6 __asm__ ("r6"); \ - register unsigned long __sc_7 __asm__ ("r7"); \ - register unsigned long __sc_8 __asm__ ("r8"); \ - \ - __sc_loadargs_##nr(name, args); \ - __asm__ __volatile__ \ - ("sc \n\t" \ - "mfcr %0 " \ - : "=&r" (__sc_0), \ - "=&r" (__sc_3), "=&r" (__sc_4), \ - "=&r" (__sc_5), "=&r" (__sc_6), \ - "=&r" (__sc_7), "=&r" (__sc_8) \ - : __sc_asm_input_##nr \ - : "cr0", "ctr", "memory", \ - "r9", "r10","r11", "r12"); \ - __sc_ret = __sc_3; \ - __sc_err = __sc_0; \ - } \ - if (__sc_err & 0x10000000) return -((int)__sc_ret); \ - return (type) __sc_ret - -#define __sc_loadargs_0(name, dummy...) \ - __sc_0 = __NR_##name -#define __sc_loadargs_1(name, arg1) \ - __sc_loadargs_0(name); \ - __sc_3 = (unsigned long) (arg1) -#define __sc_loadargs_2(name, arg1, arg2) \ - __sc_loadargs_1(name, arg1); \ - __sc_4 = (unsigned long) (arg2) -#define __sc_loadargs_3(name, arg1, arg2, arg3) \ - __sc_loadargs_2(name, arg1, arg2); \ - __sc_5 = (unsigned long) (arg3) -#define __sc_loadargs_4(name, arg1, arg2, arg3, arg4) \ - __sc_loadargs_3(name, arg1, arg2, arg3); \ - __sc_6 = (unsigned long) (arg4) -#define __sc_loadargs_5(name, arg1, arg2, arg3, arg4, arg5) \ - __sc_loadargs_4(name, arg1, arg2, arg3, arg4); \ - __sc_7 = (unsigned long) (arg5) - -#define __sc_asm_input_0 "0" (__sc_0) -#define __sc_asm_input_1 __sc_asm_input_0, "1" (__sc_3) -#define __sc_asm_input_2 __sc_asm_input_1, "2" (__sc_4) -#define __sc_asm_input_3 __sc_asm_input_2, "3" (__sc_5) -#define __sc_asm_input_4 __sc_asm_input_3, "4" (__sc_6) -#define __sc_asm_input_5 __sc_asm_input_4, "5" (__sc_7) - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ - __syscall_nr(1, type, sname, arg1); \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1, type2 arg2) \ -{ \ - __syscall_nr(2, type, sname, arg1, arg2); \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1, type2 arg2, type3 arg3) \ -{ \ - __syscall_nr(3, type, sname, arg1, arg2, arg3); \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ - __syscall_nr(4, type, sname, arg1, arg2, arg3, arg4); \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \ -{ \ - __syscall_nr(5, type, sname, arg1, arg2, arg3, arg4, arg5); \ -} +#define __NR_io_setup 227 +#define __NR_io_destroy 228 +#define __NR_io_getevents 229 +#define __NR_io_submit 230 +#define __NR_io_cancel 231 + +/* On powerpc a system call basically clobbers the same registers like a + * function call, with the exception of LR (which is needed for the + * "sc; bnslr" sequence) and CR (where only CR0.SO is clobbered to signal + * an error return status). + */ + +#define __syscall_nr(nr, type, name, args...) \ + unsigned long __sc_ret, __sc_err; \ + { \ + register unsigned long __sc_0 __asm__ ("r0"); \ + register unsigned long __sc_3 __asm__ ("r3"); \ + register unsigned long __sc_4 __asm__ ("r4"); \ + register unsigned long __sc_5 __asm__ ("r5"); \ + register unsigned long __sc_6 __asm__ ("r6"); \ + register unsigned long __sc_7 __asm__ ("r7"); \ + register unsigned long __sc_8 __asm__ ("r8"); \ + \ + __sc_loadargs_##nr(name, args); \ + __asm__ __volatile__ \ + ("sc \n\t" \ + "mfcr %0 " \ + : "=&r" (__sc_0), \ + "=&r" (__sc_3), "=&r" (__sc_4), \ + "=&r" (__sc_5), "=&r" (__sc_6), \ + "=&r" (__sc_7), "=&r" (__sc_8) \ + : __sc_asm_input_##nr \ + : "cr0", "ctr", "memory", \ + "r9", "r10","r11", "r12"); \ + __sc_ret = __sc_3; \ + __sc_err = __sc_0; \ + } \ + if (__sc_err & 0x10000000) return -((int)__sc_ret); \ + return (type) __sc_ret + +#define __sc_loadargs_0(name, dummy...) \ + __sc_0 = __NR_##name +#define __sc_loadargs_1(name, arg1) \ + __sc_loadargs_0(name); \ + __sc_3 = (unsigned long) (arg1) +#define __sc_loadargs_2(name, arg1, arg2) \ + __sc_loadargs_1(name, arg1); \ + __sc_4 = (unsigned long) (arg2) +#define __sc_loadargs_3(name, arg1, arg2, arg3) \ + __sc_loadargs_2(name, arg1, arg2); \ + __sc_5 = (unsigned long) (arg3) +#define __sc_loadargs_4(name, arg1, arg2, arg3, arg4) \ + __sc_loadargs_3(name, arg1, arg2, arg3); \ + __sc_6 = (unsigned long) (arg4) +#define __sc_loadargs_5(name, arg1, arg2, arg3, arg4, arg5) \ + __sc_loadargs_4(name, arg1, arg2, arg3, arg4); \ + __sc_7 = (unsigned long) (arg5) + +#define __sc_asm_input_0 "0" (__sc_0) +#define __sc_asm_input_1 __sc_asm_input_0, "1" (__sc_3) +#define __sc_asm_input_2 __sc_asm_input_1, "2" (__sc_4) +#define __sc_asm_input_3 __sc_asm_input_2, "3" (__sc_5) +#define __sc_asm_input_4 __sc_asm_input_3, "4" (__sc_6) +#define __sc_asm_input_5 __sc_asm_input_4, "5" (__sc_7) + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) \ +{ \ + __syscall_nr(1, type, sname, arg1); \ +} + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1, type2 arg2) \ +{ \ + __syscall_nr(2, type, sname, arg1, arg2); \ +} + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ +type fname(type1 arg1, type2 arg2, type3 arg3) \ +{ \ + __syscall_nr(3, type, sname, arg1, arg2, arg3); \ +} + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ +type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +{ \ + __syscall_nr(4, type, sname, arg1, arg2, arg3, arg4); \ +} + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ +type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \ +{ \ + __syscall_nr(5, type, sname, arg1, arg2, arg3, arg4, arg5); \ +} diff --git a/contrib/libs/libaio/syscall-s390.h b/contrib/libs/libaio/syscall-s390.h index f595810dda..3ec5ee34ee 100644 --- a/contrib/libs/libaio/syscall-s390.h +++ b/contrib/libs/libaio/syscall-s390.h @@ -1,131 +1,131 @@ -#define __NR_io_setup 243 -#define __NR_io_destroy 244 -#define __NR_io_getevents 245 -#define __NR_io_submit 246 -#define __NR_io_cancel 247 - -#define io_svc_clobber "1", "cc", "memory" - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) { \ - register type1 __arg1 asm("2") = arg1; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " .svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1, type2 arg2) { \ - register type1 __arg1 asm("2") = arg1; \ - register type2 __arg2 asm("3") = arg2; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1), \ - "d" (__arg2) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2, \ - type3,arg3) \ -type fname(type1 arg1, type2 arg2, type3 arg3) { \ - register type1 __arg1 asm("2") = arg1; \ - register type2 __arg2 asm("3") = arg2; \ - register type3 __arg3 asm("4") = arg3; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1), \ - "d" (__arg2), \ - "d" (__arg3) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2, \ - type3,arg3,type4,arg4) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ - register type1 __arg1 asm("2") = arg1; \ - register type2 __arg2 asm("3") = arg2; \ - register type3 __arg3 asm("4") = arg3; \ - register type4 __arg4 asm("5") = arg4; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1), \ - "d" (__arg2), \ - "d" (__arg3), \ - "d" (__arg4) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2, \ - type3,arg3,type4,arg4,type5,arg5) \ -type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ - type5 arg5) { \ - register type1 __arg1 asm("2") = arg1; \ - register type2 __arg2 asm("3") = arg2; \ - register type3 __arg3 asm("4") = arg3; \ - register type4 __arg4 asm("5") = arg4; \ - register type5 __arg5 asm("6") = arg5; \ - register long __svcres asm("2"); \ - long __res; \ - __asm__ __volatile__ ( \ - " .if %1 < 256\n" \ - " svc %b1\n" \ - " .else\n" \ - " la %%r1,%1\n" \ - " svc 0\n" \ - " .endif" \ - : "=d" (__svcres) \ - : "i" (__NR_##sname), \ - "0" (__arg1), \ - "d" (__arg2), \ - "d" (__arg3), \ - "d" (__arg4), \ - "d" (__arg5) \ - : io_svc_clobber ); \ - __res = __svcres; \ - return (type) __res; \ -} +#define __NR_io_setup 243 +#define __NR_io_destroy 244 +#define __NR_io_getevents 245 +#define __NR_io_submit 246 +#define __NR_io_cancel 247 + +#define io_svc_clobber "1", "cc", "memory" + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) { \ + register type1 __arg1 asm("2") = arg1; \ + register long __svcres asm("2"); \ + long __res; \ + __asm__ __volatile__ ( \ + " .if %1 < 256\n" \ + " svc %b1\n" \ + " .else\n" \ + " la %%r1,%1\n" \ + " .svc 0\n" \ + " .endif" \ + : "=d" (__svcres) \ + : "i" (__NR_##sname), \ + "0" (__arg1) \ + : io_svc_clobber ); \ + __res = __svcres; \ + return (type) __res; \ +} + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1, type2 arg2) { \ + register type1 __arg1 asm("2") = arg1; \ + register type2 __arg2 asm("3") = arg2; \ + register long __svcres asm("2"); \ + long __res; \ + __asm__ __volatile__ ( \ + " .if %1 < 256\n" \ + " svc %b1\n" \ + " .else\n" \ + " la %%r1,%1\n" \ + " svc 0\n" \ + " .endif" \ + : "=d" (__svcres) \ + : "i" (__NR_##sname), \ + "0" (__arg1), \ + "d" (__arg2) \ + : io_svc_clobber ); \ + __res = __svcres; \ + return (type) __res; \ +} + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2, \ + type3,arg3) \ +type fname(type1 arg1, type2 arg2, type3 arg3) { \ + register type1 __arg1 asm("2") = arg1; \ + register type2 __arg2 asm("3") = arg2; \ + register type3 __arg3 asm("4") = arg3; \ + register long __svcres asm("2"); \ + long __res; \ + __asm__ __volatile__ ( \ + " .if %1 < 256\n" \ + " svc %b1\n" \ + " .else\n" \ + " la %%r1,%1\n" \ + " svc 0\n" \ + " .endif" \ + : "=d" (__svcres) \ + : "i" (__NR_##sname), \ + "0" (__arg1), \ + "d" (__arg2), \ + "d" (__arg3) \ + : io_svc_clobber ); \ + __res = __svcres; \ + return (type) __res; \ +} + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2, \ + type3,arg3,type4,arg4) \ +type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + register type1 __arg1 asm("2") = arg1; \ + register type2 __arg2 asm("3") = arg2; \ + register type3 __arg3 asm("4") = arg3; \ + register type4 __arg4 asm("5") = arg4; \ + register long __svcres asm("2"); \ + long __res; \ + __asm__ __volatile__ ( \ + " .if %1 < 256\n" \ + " svc %b1\n" \ + " .else\n" \ + " la %%r1,%1\n" \ + " svc 0\n" \ + " .endif" \ + : "=d" (__svcres) \ + : "i" (__NR_##sname), \ + "0" (__arg1), \ + "d" (__arg2), \ + "d" (__arg3), \ + "d" (__arg4) \ + : io_svc_clobber ); \ + __res = __svcres; \ + return (type) __res; \ +} + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2, \ + type3,arg3,type4,arg4,type5,arg5) \ +type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5) { \ + register type1 __arg1 asm("2") = arg1; \ + register type2 __arg2 asm("3") = arg2; \ + register type3 __arg3 asm("4") = arg3; \ + register type4 __arg4 asm("5") = arg4; \ + register type5 __arg5 asm("6") = arg5; \ + register long __svcres asm("2"); \ + long __res; \ + __asm__ __volatile__ ( \ + " .if %1 < 256\n" \ + " svc %b1\n" \ + " .else\n" \ + " la %%r1,%1\n" \ + " svc 0\n" \ + " .endif" \ + : "=d" (__svcres) \ + : "i" (__NR_##sname), \ + "0" (__arg1), \ + "d" (__arg2), \ + "d" (__arg3), \ + "d" (__arg4), \ + "d" (__arg5) \ + : io_svc_clobber ); \ + __res = __svcres; \ + return (type) __res; \ +} diff --git a/contrib/libs/libaio/syscall-sparc.h b/contrib/libs/libaio/syscall-sparc.h index f93c2a29c3..dd8033d015 100644 --- a/contrib/libs/libaio/syscall-sparc.h +++ b/contrib/libs/libaio/syscall-sparc.h @@ -1,103 +1,103 @@ -#include <errno.h> - -#define __NR_io_setup 268 -#define __NR_io_destroy 269 -#define __NR_io_submit 270 -#define __NR_io_cancel 271 -#define __NR_io_getevents 272 - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -register long __o2 __asm__ ("o2") = (long)(arg3); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -register long __o2 __asm__ ("o2") = (long)(arg3); \ -register long __o3 __asm__ ("o3") = (long)(arg4); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##sname; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -register long __o2 __asm__ ("o2") = (long)(arg3); \ -register long __o3 __asm__ ("o3") = (long)(arg4); \ -register long __o4 __asm__ ("o4") = (long)(arg5); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__g1) \ - : "cc"); \ -return (type) __res; \ -} +#include <errno.h> + +#define __NR_io_setup 268 +#define __NR_io_destroy 269 +#define __NR_io_submit 270 +#define __NR_io_cancel 271 +#define __NR_io_getevents 272 + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) \ +{ \ +long __res; \ +register long __g1 __asm__ ("g1") = __NR_##sname; \ +register long __o0 __asm__ ("o0") = (long)(arg1); \ +__asm__ __volatile__ ("t 0x10\n\t" \ + "bcc 1f\n\t" \ + "mov %%o0, %0\n\t" \ + "sub %%g0, %%o0, %0\n\t" \ + "1:\n\t" \ + : "=r" (__res), "=&r" (__o0) \ + : "1" (__o0), "r" (__g1) \ + : "cc"); \ +return (type) __res; \ +} + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1,type2 arg2) \ +{ \ +long __res; \ +register long __g1 __asm__ ("g1") = __NR_##sname; \ +register long __o0 __asm__ ("o0") = (long)(arg1); \ +register long __o1 __asm__ ("o1") = (long)(arg2); \ +__asm__ __volatile__ ("t 0x10\n\t" \ + "bcc 1f\n\t" \ + "mov %%o0, %0\n\t" \ + "sub %%g0, %%o0, %0\n\t" \ + "1:\n\t" \ + : "=r" (__res), "=&r" (__o0) \ + : "1" (__o0), "r" (__o1), "r" (__g1) \ + : "cc"); \ +return (type) __res; \ +} + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ +type fname(type1 arg1,type2 arg2,type3 arg3) \ +{ \ +long __res; \ +register long __g1 __asm__ ("g1") = __NR_##sname; \ +register long __o0 __asm__ ("o0") = (long)(arg1); \ +register long __o1 __asm__ ("o1") = (long)(arg2); \ +register long __o2 __asm__ ("o2") = (long)(arg3); \ +__asm__ __volatile__ ("t 0x10\n\t" \ + "bcc 1f\n\t" \ + "mov %%o0, %0\n\t" \ + "sub %%g0, %%o0, %0\n\t" \ + "1:\n\t" \ + : "=r" (__res), "=&r" (__o0) \ + : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) \ + : "cc"); \ +return (type) __res; \ +} + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ +type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +{ \ +long __res; \ +register long __g1 __asm__ ("g1") = __NR_##sname; \ +register long __o0 __asm__ ("o0") = (long)(arg1); \ +register long __o1 __asm__ ("o1") = (long)(arg2); \ +register long __o2 __asm__ ("o2") = (long)(arg3); \ +register long __o3 __asm__ ("o3") = (long)(arg4); \ +__asm__ __volatile__ ("t 0x10\n\t" \ + "bcc 1f\n\t" \ + "mov %%o0, %0\n\t" \ + "sub %%g0, %%o0, %0\n\t" \ + "1:\n\t" \ + : "=r" (__res), "=&r" (__o0) \ + : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__g1) \ + : "cc"); \ +return (type) __res; \ +} + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ +type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ +{ \ +long __res; \ +register long __g1 __asm__ ("g1") = __NR_##sname; \ +register long __o0 __asm__ ("o0") = (long)(arg1); \ +register long __o1 __asm__ ("o1") = (long)(arg2); \ +register long __o2 __asm__ ("o2") = (long)(arg3); \ +register long __o3 __asm__ ("o3") = (long)(arg4); \ +register long __o4 __asm__ ("o4") = (long)(arg5); \ +__asm__ __volatile__ ("t 0x10\n\t" \ + "bcc 1f\n\t" \ + "mov %%o0, %0\n\t" \ + "sub %%g0, %%o0, %0\n\t" \ + "1:\n\t" \ + : "=r" (__res), "=&r" (__o0) \ + : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__g1) \ + : "cc"); \ +return (type) __res; \ +} diff --git a/contrib/libs/libaio/syscall-x86_64.h b/contrib/libs/libaio/syscall-x86_64.h index 7e85d7f339..9361856723 100644 --- a/contrib/libs/libaio/syscall-x86_64.h +++ b/contrib/libs/libaio/syscall-x86_64.h @@ -1,63 +1,63 @@ -#define __NR_io_setup 206 -#define __NR_io_destroy 207 -#define __NR_io_getevents 208 -#define __NR_io_submit 209 -#define __NR_io_cancel 210 - -#define __syscall_clobber "r11","rcx","memory" -#define __syscall "syscall" - -#define io_syscall1(type,fname,sname,type1,arg1) \ -type fname(type1 arg1) \ -{ \ -long __res; \ -__asm__ volatile (__syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)) : __syscall_clobber ); \ -return __res; \ -} - -#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ -type fname(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -__asm__ volatile (__syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)) : __syscall_clobber ); \ -return __res; \ -} - -#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ -type fname(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -__asm__ volatile (__syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)), \ - "d" ((long)(arg3)) : __syscall_clobber); \ -return __res; \ -} - -#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -__asm__ volatile ("movq %5,%%r10 ;" __syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)), \ - "d" ((long)(arg3)),"g" ((long)(arg4)) : __syscall_clobber,"r10" ); \ -return __res; \ -} - -#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -__asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall \ - : "=a" (__res) \ - : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)), \ - "d" ((long)(arg3)),"g" ((long)(arg4)),"g" ((long)(arg5)) : \ - __syscall_clobber,"r8","r10" ); \ -return __res; \ +#define __NR_io_setup 206 +#define __NR_io_destroy 207 +#define __NR_io_getevents 208 +#define __NR_io_submit 209 +#define __NR_io_cancel 210 + +#define __syscall_clobber "r11","rcx","memory" +#define __syscall "syscall" + +#define io_syscall1(type,fname,sname,type1,arg1) \ +type fname(type1 arg1) \ +{ \ +long __res; \ +__asm__ volatile (__syscall \ + : "=a" (__res) \ + : "0" (__NR_##sname),"D" ((long)(arg1)) : __syscall_clobber ); \ +return __res; \ +} + +#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \ +type fname(type1 arg1,type2 arg2) \ +{ \ +long __res; \ +__asm__ volatile (__syscall \ + : "=a" (__res) \ + : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)) : __syscall_clobber ); \ +return __res; \ +} + +#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \ +type fname(type1 arg1,type2 arg2,type3 arg3) \ +{ \ +long __res; \ +__asm__ volatile (__syscall \ + : "=a" (__res) \ + : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)), \ + "d" ((long)(arg3)) : __syscall_clobber); \ +return __res; \ +} + +#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ +type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +{ \ +long __res; \ +__asm__ volatile ("movq %5,%%r10 ;" __syscall \ + : "=a" (__res) \ + : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)), \ + "d" ((long)(arg3)),"g" ((long)(arg4)) : __syscall_clobber,"r10" ); \ +return __res; \ } + +#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ +type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ +{ \ +long __res; \ +__asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall \ + : "=a" (__res) \ + : "0" (__NR_##sname),"D" ((long)(arg1)),"S" ((long)(arg2)), \ + "d" ((long)(arg3)),"g" ((long)(arg4)),"g" ((long)(arg5)) : \ + __syscall_clobber,"r8","r10" ); \ +return __res; \ +} diff --git a/contrib/libs/libaio/syscall.h b/contrib/libs/libaio/syscall.h index 9cbde2d8f8..a2da0307a0 100644 --- a/contrib/libs/libaio/syscall.h +++ b/contrib/libs/libaio/syscall.h @@ -1,34 +1,34 @@ -#include <sys/syscall.h> -#include <unistd.h> - -#define _SYMSTR(str) #str -#define SYMSTR(str) _SYMSTR(str) - -#define SYMVER(compat_sym, orig_sym, ver_sym) \ - __asm__(".symver " SYMSTR(compat_sym) "," SYMSTR(orig_sym) "@LIBAIO_" SYMSTR(ver_sym)); - -#define DEFSYMVER(compat_sym, orig_sym, ver_sym) \ - __asm__(".symver " SYMSTR(compat_sym) "," SYMSTR(orig_sym) "@@LIBAIO_" SYMSTR(ver_sym)); - -#if defined(__i386__) -#include "syscall-i386.h" -#elif defined(__x86_64__) -#include "syscall-x86_64.h" -#elif defined(__ia64__) -#include "syscall-ia64.h" -#elif defined(__PPC__) -#include "syscall-ppc.h" -#elif defined(__s390__) -#include "syscall-s390.h" -#elif defined(__alpha__) -#include "syscall-alpha.h" -#elif defined(__arm__) -#include "syscall-arm.h" -#elif defined(__sparc__) -#include "syscall-sparc.h" -#elif defined(__aarch64__) -#include "syscall-arm64.h" -#else -#warning "using generic syscall method" -#include "syscall-generic.h" -#endif +#include <sys/syscall.h> +#include <unistd.h> + +#define _SYMSTR(str) #str +#define SYMSTR(str) _SYMSTR(str) + +#define SYMVER(compat_sym, orig_sym, ver_sym) \ + __asm__(".symver " SYMSTR(compat_sym) "," SYMSTR(orig_sym) "@LIBAIO_" SYMSTR(ver_sym)); + +#define DEFSYMVER(compat_sym, orig_sym, ver_sym) \ + __asm__(".symver " SYMSTR(compat_sym) "," SYMSTR(orig_sym) "@@LIBAIO_" SYMSTR(ver_sym)); + +#if defined(__i386__) +#include "syscall-i386.h" +#elif defined(__x86_64__) +#include "syscall-x86_64.h" +#elif defined(__ia64__) +#include "syscall-ia64.h" +#elif defined(__PPC__) +#include "syscall-ppc.h" +#elif defined(__s390__) +#include "syscall-s390.h" +#elif defined(__alpha__) +#include "syscall-alpha.h" +#elif defined(__arm__) +#include "syscall-arm.h" +#elif defined(__sparc__) +#include "syscall-sparc.h" +#elif defined(__aarch64__) +#include "syscall-arm64.h" +#else +#warning "using generic syscall method" +#include "syscall-generic.h" +#endif diff --git a/contrib/libs/libaio/vsys_def.h b/contrib/libs/libaio/vsys_def.h index 1e93433572..13d032e330 100644 --- a/contrib/libs/libaio/vsys_def.h +++ b/contrib/libs/libaio/vsys_def.h @@ -1,24 +1,24 @@ -/* libaio Linux async I/O interface - Copyright 2002 Red Hat, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -extern int vsys_io_setup(unsigned nr_reqs, io_context_t *ctxp); -extern int vsys_io_destroy(io_context_t ctx); -extern int vsys_io_submit(io_context_t ctx, long nr, struct iocb *iocbs[]); -extern int vsys_io_cancel(io_context_t ctx, struct iocb *iocb); -extern int vsys_io_wait(io_context_t ctx, struct iocb *iocb, const struct timespec *when); -extern int vsys_io_getevents(io_context_t ctx_id, long nr, struct io_event *events, const struct timespec *timeout); - +/* libaio Linux async I/O interface + Copyright 2002 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +extern int vsys_io_setup(unsigned nr_reqs, io_context_t *ctxp); +extern int vsys_io_destroy(io_context_t ctx); +extern int vsys_io_submit(io_context_t ctx, long nr, struct iocb *iocbs[]); +extern int vsys_io_cancel(io_context_t ctx, struct iocb *iocb); +extern int vsys_io_wait(io_context_t ctx, struct iocb *iocb, const struct timespec *when); +extern int vsys_io_getevents(io_context_t ctx_id, long nr, struct io_event *events, const struct timespec *timeout); + diff --git a/contrib/libs/libaio/ya.make b/contrib/libs/libaio/ya.make index 3d5448860d..3eb09b549b 100644 --- a/contrib/libs/libaio/ya.make +++ b/contrib/libs/libaio/ya.make @@ -1,5 +1,5 @@ -LIBRARY() - +LIBRARY() + # git repository: https://pagure.io/libaio.git # revision: 5a546a834c36070648158d19dd564762d59f8eb8 @@ -13,9 +13,9 @@ OWNER( g:contrib g:cpp-contrib ) - -NO_RUNTIME() - + +NO_RUNTIME() + IF (USE_DYNAMIC_AIO) PEERDIR( contrib/libs/libaio/dynamic @@ -25,8 +25,8 @@ ELSE() contrib/libs/libaio/static ) ENDIF() - -END() + +END() RECURSE( dynamic diff --git a/contrib/libs/ya.make b/contrib/libs/ya.make index 7ef41e85f9..9c4640fdcf 100644 --- a/contrib/libs/ya.make +++ b/contrib/libs/ya.make @@ -395,7 +395,7 @@ IF (OS_LINUX) proc luajit luajit_21 - libaio + libaio libcap libmnl libnfnetlink @@ -405,7 +405,7 @@ IF (OS_LINUX) sdbus-cpp systemd uuid - virtiofsd + virtiofsd ) ENDIF() @@ -440,7 +440,7 @@ IF (OS_IOS AND ARCH_ARM64 OR OS_DARWIN) MoltenVK ) ENDIF() - + IF (MUSL) RECURSE(musl_extra) ENDIF() diff --git a/contrib/restricted/ya.make b/contrib/restricted/ya.make index d0c0edcfdd..b52a206733 100644 --- a/contrib/restricted/ya.make +++ b/contrib/restricted/ya.make @@ -32,18 +32,18 @@ RECURSE( keyutils libelf libffi - libiscsi - libntirpc + libiscsi + libntirpc librseq libsigcxx libsoup libtorrent - liburcu + liburcu libxsmm llhttp mpg123 murmurhash - nfs_ganesha + nfs_ganesha noc openal-soft patched diff --git a/contrib/tools/ya.make b/contrib/tools/ya.make index 4979a3cd39..750911c587 100644 --- a/contrib/tools/ya.make +++ b/contrib/tools/ya.make @@ -18,7 +18,7 @@ RECURSE( grpc_cli kyotocabinet langid - leveldb + leveldb lld lldb mp4viewer @@ -39,7 +39,7 @@ RECURSE( swig tf tpce-benchmark - tpch-benchmark + tpch-benchmark tre unbound unbound/build diff --git a/library/cpp/actors/core/executor_thread.cpp b/library/cpp/actors/core/executor_thread.cpp index ebfb8599b3..446b651efd 100644 --- a/library/cpp/actors/core/executor_thread.cpp +++ b/library/cpp/actors/core/executor_thread.cpp @@ -4,12 +4,12 @@ #include "mailbox.h" #include "event.h" #include "events.h" - + #include <library/cpp/actors/prof/tag.h> #include <library/cpp/actors/util/affinity.h> #include <library/cpp/actors/util/datetime.h> #include <library/cpp/actors/util/thread.h> - + #ifdef BALLOC #include <library/cpp/balloc/optional/operators.h> #endif @@ -174,8 +174,8 @@ namespace NActors { if (activityType != prevActivityType) { prevActivityType = activityType; NProfiling::TMemoryTagScope::Reset(ActorSystem->MemProfActivityBase + activityType); - } - + } + actor->Receive(ev, ctx); size_t dyingActorsCnt = DyingActors.size(); diff --git a/library/cpp/actors/core/log.cpp b/library/cpp/actors/core/log.cpp index 651c04cc11..5f63b5af58 100644 --- a/library/cpp/actors/core/log.cpp +++ b/library/cpp/actors/core/log.cpp @@ -171,21 +171,21 @@ namespace NActors { TIntrusivePtr<NMonitoring::TDynamicCounters> counters) : TActor(&TLoggerActor::StateFunc) , Settings(settings) - , LogBackend(logBackend.Release()) + , LogBackend(logBackend.Release()) , Metrics(std::make_unique<TLoggerCounters>(counters)) { - } - - TLoggerActor::TLoggerActor(TIntrusivePtr<NLog::TSettings> settings, - std::shared_ptr<TLogBackend> logBackend, - TIntrusivePtr<NMonitoring::TDynamicCounters> counters) - : TActor(&TLoggerActor::StateFunc) - , Settings(settings) - , LogBackend(logBackend) + } + + TLoggerActor::TLoggerActor(TIntrusivePtr<NLog::TSettings> settings, + std::shared_ptr<TLogBackend> logBackend, + TIntrusivePtr<NMonitoring::TDynamicCounters> counters) + : TActor(&TLoggerActor::StateFunc) + , Settings(settings) + , LogBackend(logBackend) , Metrics(std::make_unique<TLoggerCounters>(counters)) - { - } - + { + } + TLoggerActor::TLoggerActor(TIntrusivePtr<NLog::TSettings> settings, TAutoPtr<TLogBackend> logBackend, std::shared_ptr<NMonitoring::TMetricRegistry> metrics) @@ -193,7 +193,7 @@ namespace NActors { , Settings(settings) , LogBackend(logBackend.Release()) , Metrics(std::make_unique<TLoggerMetrics>(metrics)) - { + { } TLoggerActor::TLoggerActor(TIntrusivePtr<NLog::TSettings> settings, @@ -580,31 +580,31 @@ namespace NActors { char buf[TimeBufSize]; switch (Settings->Format) { - case NActors::NLog::TSettings::PLAIN_FULL_FORMAT: { - TStringBuilder logRecord; - if (Settings->UseLocalTimestamps) { + case NActors::NLog::TSettings::PLAIN_FULL_FORMAT: { + TStringBuilder logRecord; + if (Settings->UseLocalTimestamps) { logRecord << FormatLocalTimestamp(time, buf); - } else { - logRecord << time; - } - logRecord + } else { + logRecord << time; + } + logRecord << Settings->MessagePrefix - << " :" << Settings->ComponentName(component) - << " " << PriorityToString(priority) - << ": " << formatted; - LogBackend->WriteData( - TLogRecord(logPrio, logRecord.data(), logRecord.size())); - } break; - - case NActors::NLog::TSettings::PLAIN_SHORT_FORMAT: { - TStringBuilder logRecord; - logRecord - << Settings->ComponentName(component) - << ": " << formatted; - LogBackend->WriteData( - TLogRecord(logPrio, logRecord.data(), logRecord.size())); - } break; - + << " :" << Settings->ComponentName(component) + << " " << PriorityToString(priority) + << ": " << formatted; + LogBackend->WriteData( + TLogRecord(logPrio, logRecord.data(), logRecord.size())); + } break; + + case NActors::NLog::TSettings::PLAIN_SHORT_FORMAT: { + TStringBuilder logRecord; + logRecord + << Settings->ComponentName(component) + << ": " << formatted; + LogBackend->WriteData( + TLogRecord(logPrio, logRecord.data(), logRecord.size())); + } break; + case NActors::NLog::TSettings::JSON_FORMAT: { NJsonWriter::TBuf json; json.BeginObject() @@ -629,9 +629,9 @@ namespace NActors { .WriteKey("message") .WriteString(formatted) .EndObject(); - auto logRecord = json.Str(); - LogBackend->WriteData( - TLogRecord(logPrio, logRecord.data(), logRecord.size())); + auto logRecord = json.Str(); + LogBackend->WriteData( + TLogRecord(logPrio, logRecord.data(), logRecord.size())); } break; } diff --git a/library/cpp/actors/core/log.h b/library/cpp/actors/core/log.h index d4047e8164..c11a7cf3c1 100644 --- a/library/cpp/actors/core/log.h +++ b/library/cpp/actors/core/log.h @@ -199,9 +199,9 @@ namespace NActors { TLoggerActor(TIntrusivePtr<NLog::TSettings> settings, TAutoPtr<TLogBackend> logBackend, TIntrusivePtr<NMonitoring::TDynamicCounters> counters); - TLoggerActor(TIntrusivePtr<NLog::TSettings> settings, - std::shared_ptr<TLogBackend> logBackend, - TIntrusivePtr<NMonitoring::TDynamicCounters> counters); + TLoggerActor(TIntrusivePtr<NLog::TSettings> settings, + std::shared_ptr<TLogBackend> logBackend, + TIntrusivePtr<NMonitoring::TDynamicCounters> counters); TLoggerActor(TIntrusivePtr<NLog::TSettings> settings, TAutoPtr<TLogBackend> logBackend, std::shared_ptr<NMonitoring::TMetricRegistry> metrics); @@ -236,9 +236,9 @@ namespace NActors { private: TIntrusivePtr<NLog::TSettings> Settings; - std::shared_ptr<TLogBackend> LogBackend; - ui64 IgnoredCount = 0; - ui64 PassedCount = 0; + std::shared_ptr<TLogBackend> LogBackend; + ui64 IgnoredCount = 0; + ui64 PassedCount = 0; static TAtomic IsOverflow; TDuration WakeupInterval{TDuration::Seconds(5)}; std::unique_ptr<ILoggerMetrics> Metrics; diff --git a/library/cpp/actors/core/mon.h b/library/cpp/actors/core/mon.h index 4bf41e8c63..c450f2338e 100644 --- a/library/cpp/actors/core/mon.h +++ b/library/cpp/actors/core/mon.h @@ -42,11 +42,11 @@ namespace NActors { // base class for HTTP info response struct IEvHttpInfoRes: public NActors::TEventLocal<IEvHttpInfoRes, HttpInfoRes> { - enum EContentType { - Html, - Custom, - }; - + enum EContentType { + Html, + Custom, + }; + IEvHttpInfoRes() { } @@ -54,7 +54,7 @@ namespace NActors { } virtual void Output(IOutputStream& out) const = 0; - virtual EContentType GetContentType() const = 0; + virtual EContentType GetContentType() const = 0; }; // Ready to output HTML in TString @@ -62,7 +62,7 @@ namespace NActors { TEvHttpInfoRes(const TString& answer, int subReqId = 0, EContentType contentType = Html) : Answer(answer) , SubRequestId(subReqId) - , ContentType(contentType) + , ContentType(contentType) { } @@ -70,13 +70,13 @@ namespace NActors { out << Answer; } - EContentType GetContentType() const override { - return ContentType; - } - + EContentType GetContentType() const override { + return ContentType; + } + const TString Answer; const int SubRequestId; - const EContentType ContentType; + const EContentType ContentType; }; struct TEvRemoteHttpInfo: public NActors::TEventBase<TEvRemoteHttpInfo, RemoteHttpInfo> { diff --git a/library/cpp/actors/core/ya.make b/library/cpp/actors/core/ya.make index e534912e7c..880a9d00db 100644 --- a/library/cpp/actors/core/ya.make +++ b/library/cpp/actors/core/ya.make @@ -7,10 +7,10 @@ OWNER( NO_WSHADOW() -IF (PROFILE_MEMORY_ALLOCATIONS) - CFLAGS(-DPROFILE_MEMORY_ALLOCATIONS) -ENDIF() - +IF (PROFILE_MEMORY_ALLOCATIONS) + CFLAGS(-DPROFILE_MEMORY_ALLOCATIONS) +ENDIF() + IF (ALLOCATOR == "B" OR ALLOCATOR == "BS" OR ALLOCATOR == "C") CXXFLAGS(-DBALLOC) PEERDIR( diff --git a/library/cpp/actors/interconnect/events_local.h b/library/cpp/actors/interconnect/events_local.h index bf05879b5b..8a46ffd535 100644 --- a/library/cpp/actors/interconnect/events_local.h +++ b/library/cpp/actors/interconnect/events_local.h @@ -216,7 +216,7 @@ namespace NActors { HANDSHAKE_FAIL_SESSION_MISMATCH, }; - TEvHandshakeFail(EnumHandshakeFail temporary, TString explanation) + TEvHandshakeFail(EnumHandshakeFail temporary, TString explanation) : Temporary(temporary) , Explanation(std::move(explanation)) { diff --git a/library/cpp/actors/interconnect/poller_tcp_unit.cpp b/library/cpp/actors/interconnect/poller_tcp_unit.cpp index 2ec9339115..59e7dda810 100644 --- a/library/cpp/actors/interconnect/poller_tcp_unit.cpp +++ b/library/cpp/actors/interconnect/poller_tcp_unit.cpp @@ -9,7 +9,7 @@ #include <library/cpp/actors/prof/tag.h> #include <library/cpp/actors/util/intrinsics.h> - + #if defined _linux_ #include <pthread.h> #endif @@ -101,7 +101,7 @@ namespace NInterconnect { template <> void TPollerUnit::RunLoop<false>() { - NProfiling::TMemoryTagScope tag("INTERCONNECT_RECEIVED_DATA"); + NProfiling::TMemoryTagScope tag("INTERCONNECT_RECEIVED_DATA"); while (!AtomicLoad(&StopFlag)) ProcessRead(); } @@ -109,7 +109,7 @@ namespace NInterconnect { template <> void TPollerUnit::RunLoop<true>() { - NProfiling::TMemoryTagScope tag("INTERCONNECT_SEND_DATA"); + NProfiling::TMemoryTagScope tag("INTERCONNECT_SEND_DATA"); while (!AtomicLoad(&StopFlag)) ProcessWrite(); } diff --git a/library/cpp/actors/interconnect/ut/lib/node.h b/library/cpp/actors/interconnect/ut/lib/node.h index 496a54c1c9..ff30b1445e 100644 --- a/library/cpp/actors/interconnect/ut/lib/node.h +++ b/library/cpp/actors/interconnect/ut/lib/node.h @@ -66,26 +66,26 @@ public: constexpr ui32 LoggerComponentId = 410; // NKikimrServices::LOGGER auto loggerSettings = MakeIntrusive<NLog::TSettings>( - loggerActorId, + loggerActorId, (NLog::EComponent)LoggerComponentId, NLog::PRI_INFO, NLog::PRI_DEBUG, - 0U); - - loggerSettings->Append( - NActorsServices::EServiceCommon_MIN, + 0U); + + loggerSettings->Append( + NActorsServices::EServiceCommon_MIN, NActorsServices::EServiceCommon_MAX, NActorsServices::EServiceCommon_Name ); - + constexpr ui32 WilsonComponentId = 430; // NKikimrServices::WILSON - static const TString WilsonComponentName = "WILSON"; - - loggerSettings->Append( + static const TString WilsonComponentName = "WILSON"; + + loggerSettings->Append( (NLog::EComponent)WilsonComponentId, (NLog::EComponent)WilsonComponentId + 1, [](NLog::EComponent) -> const TString & { return WilsonComponentName; }); - + // register nameserver table auto names = MakeIntrusive<TTableNameserverSetup>(); for (ui32 i = 1; i <= numNodes; ++i) { diff --git a/library/cpp/actors/interconnect/ya.make b/library/cpp/actors/interconnect/ya.make index 80055e4245..60d29b0fc0 100644 --- a/library/cpp/actors/interconnect/ya.make +++ b/library/cpp/actors/interconnect/ya.make @@ -8,10 +8,10 @@ OWNER( NO_WSHADOW() -IF (PROFILE_MEMORY_ALLOCATIONS) - CFLAGS(-DPROFILE_MEMORY_ALLOCATIONS) -ENDIF() - +IF (PROFILE_MEMORY_ALLOCATIONS) + CFLAGS(-DPROFILE_MEMORY_ALLOCATIONS) +ENDIF() + SRCS( channel_scheduler.h event_filter.h diff --git a/library/cpp/actors/prof/tag.cpp b/library/cpp/actors/prof/tag.cpp index ff4ea01f3c..9ccf03e1a9 100644 --- a/library/cpp/actors/prof/tag.cpp +++ b/library/cpp/actors/prof/tag.cpp @@ -4,108 +4,108 @@ #include <library/cpp/charset/ci_string.h> #include <library/cpp/containers/atomizer/atomizer.h> #include <library/cpp/malloc/api/malloc.h> - -#if defined(PROFILE_MEMORY_ALLOCATIONS) + +#if defined(PROFILE_MEMORY_ALLOCATIONS) #include <library/cpp/lfalloc/dbg_info/dbg_info.h> #include <library/cpp/ytalloc/api/ytalloc.h> -#endif - -#include <util/generic/singleton.h> -#include <util/generic/string.h> -#include <util/generic/vector.h> +#endif + +#include <util/generic/singleton.h> +#include <util/generic/string.h> +#include <util/generic/vector.h> #include <util/system/mutex.h> namespace NProfiling { - class TStringAtoms { - private: + class TStringAtoms { + private: TMutex Mutex; atomizer<ci_hash, ci_equal_to> Tags; - - public: - static TStringAtoms& Instance() { - return *Singleton<TStringAtoms>(); - } - - ui32 MakeTag(const char* s) { - Y_VERIFY(s); - with_lock (Mutex) { - return Tags.string_to_atom(s); - } - } - - ui32 MakeTags(const TVector<const char*>& ss) { - Y_VERIFY(ss); - with_lock (Mutex) { - ui32 baseTag = Tags.string_to_atom(ss[0]); - ui32 nextTag = baseTag + 1; - for (auto i = ss.begin() + 1; i != ss.end(); ++i, ++nextTag) { - Y_VERIFY(*i); - ui32 ctag = Tags.string_to_atom(*i); - Y_VERIFY(ctag == nextTag); - } - return baseTag; - } - } - - const char* GetTag(ui32 tag) const { - with_lock (Mutex) { - return Tags.get_atom_name(tag); - } - } - - size_t GetTagsCount() const { - with_lock (Mutex) { - return Tags.size(); - } - } + + public: + static TStringAtoms& Instance() { + return *Singleton<TStringAtoms>(); + } + + ui32 MakeTag(const char* s) { + Y_VERIFY(s); + with_lock (Mutex) { + return Tags.string_to_atom(s); + } + } + + ui32 MakeTags(const TVector<const char*>& ss) { + Y_VERIFY(ss); + with_lock (Mutex) { + ui32 baseTag = Tags.string_to_atom(ss[0]); + ui32 nextTag = baseTag + 1; + for (auto i = ss.begin() + 1; i != ss.end(); ++i, ++nextTag) { + Y_VERIFY(*i); + ui32 ctag = Tags.string_to_atom(*i); + Y_VERIFY(ctag == nextTag); + } + return baseTag; + } + } + + const char* GetTag(ui32 tag) const { + with_lock (Mutex) { + return Tags.get_atom_name(tag); + } + } + + size_t GetTagsCount() const { + with_lock (Mutex) { + return Tags.size(); + } + } }; ui32 MakeTag(const char* s) { - return TStringAtoms::Instance().MakeTag(s); + return TStringAtoms::Instance().MakeTag(s); } ui32 MakeTags(const TVector<const char*>& ss) { - return TStringAtoms::Instance().MakeTags(ss); + return TStringAtoms::Instance().MakeTags(ss); } const char* GetTag(ui32 tag) { - return TStringAtoms::Instance().GetTag(tag); + return TStringAtoms::Instance().GetTag(tag); + } + + size_t GetTagsCount() { + return TStringAtoms::Instance().GetTagsCount(); } - size_t GetTagsCount() { - return TStringAtoms::Instance().GetTagsCount(); - } - static ui32 SetThreadAllocTag_Default(ui32 tag) { Y_UNUSED(tag); return 0; } -#if defined(PROFILE_MEMORY_ALLOCATIONS) - static ui32 SetThreadAllocTag_YT(ui32 tag) { - auto prev = NYT::NYTAlloc::GetCurrentMemoryTag(); - NYT::NYTAlloc::SetCurrentMemoryTag(tag); - return prev; - } - - static TSetThreadAllocTag* SetThreadAllocTagFn() { - const auto& info = NMalloc::MallocInfo(); - - TStringBuf name(info.Name); - if (name.StartsWith("lf")) { - return (TSetThreadAllocTag*)NAllocDbg::SetThreadAllocTag; - } else if (name.StartsWith("yt")) { - return SetThreadAllocTag_YT; +#if defined(PROFILE_MEMORY_ALLOCATIONS) + static ui32 SetThreadAllocTag_YT(ui32 tag) { + auto prev = NYT::NYTAlloc::GetCurrentMemoryTag(); + NYT::NYTAlloc::SetCurrentMemoryTag(tag); + return prev; + } + + static TSetThreadAllocTag* SetThreadAllocTagFn() { + const auto& info = NMalloc::MallocInfo(); + + TStringBuf name(info.Name); + if (name.StartsWith("lf")) { + return (TSetThreadAllocTag*)NAllocDbg::SetThreadAllocTag; + } else if (name.StartsWith("yt")) { + return SetThreadAllocTag_YT; } else if (name.StartsWith("tc")) { return SetTCMallocThreadAllocTag; - } else { - return SetThreadAllocTag_Default; - } - } + } else { + return SetThreadAllocTag_Default; + } + } #else static TSetThreadAllocTag* SetThreadAllocTagFn() { const auto& info = NMalloc::MallocInfo(); - + TStringBuf name(info.Name); if (name.StartsWith("tc")) { return SetTCMallocThreadAllocTag; @@ -115,5 +115,5 @@ namespace NProfiling { } #endif - TSetThreadAllocTag* SetThreadAllocTag = SetThreadAllocTagFn(); + TSetThreadAllocTag* SetThreadAllocTag = SetThreadAllocTagFn(); } diff --git a/library/cpp/actors/prof/tag.h b/library/cpp/actors/prof/tag.h index 5ef36f588b..357e264a22 100644 --- a/library/cpp/actors/prof/tag.h +++ b/library/cpp/actors/prof/tag.h @@ -1,6 +1,6 @@ #pragma once -#include <util/generic/fwd.h> +#include <util/generic/fwd.h> /* Common registry for tagging memory profiler. @@ -15,21 +15,21 @@ namespace NProfiling { ui32 MakeTags(const TVector<const char*>& ss); const char* GetTag(ui32 tag); - size_t GetTagsCount(); + size_t GetTagsCount(); + + using TSetThreadAllocTag = ui32(ui32 tag); + extern TSetThreadAllocTag* SetThreadAllocTag; - using TSetThreadAllocTag = ui32(ui32 tag); - extern TSetThreadAllocTag* SetThreadAllocTag; - class TMemoryTagScope { public: explicit TMemoryTagScope(ui32 tag) - : RestoreTag(SetThreadAllocTag(tag)) + : RestoreTag(SetThreadAllocTag(tag)) { } - + explicit TMemoryTagScope(const char* tagName) { ui32 newTag = MakeTag(tagName); - RestoreTag = SetThreadAllocTag(newTag); + RestoreTag = SetThreadAllocTag(newTag); } TMemoryTagScope(TMemoryTagScope&& move) @@ -47,20 +47,20 @@ namespace NProfiling { } static void Reset(ui32 tag) { - SetThreadAllocTag(tag); + SetThreadAllocTag(tag); } void Release() { if (!Released) { - SetThreadAllocTag(RestoreTag); + SetThreadAllocTag(RestoreTag); Released = true; } } - ~TMemoryTagScope() { + ~TMemoryTagScope() { if (!Released) { - SetThreadAllocTag(RestoreTag); - } + SetThreadAllocTag(RestoreTag); + } } protected: diff --git a/library/cpp/actors/prof/ya.make b/library/cpp/actors/prof/ya.make index 4d15d4e962..b5e2497563 100644 --- a/library/cpp/actors/prof/ya.make +++ b/library/cpp/actors/prof/ya.make @@ -14,15 +14,15 @@ PEERDIR( library/cpp/containers/atomizer ) -IF (PROFILE_MEMORY_ALLOCATIONS) +IF (PROFILE_MEMORY_ALLOCATIONS) CFLAGS(-DPROFILE_MEMORY_ALLOCATIONS) - PEERDIR( + PEERDIR( library/cpp/malloc/api library/cpp/lfalloc/dbg_info library/cpp/ytalloc/api - ) -ENDIF() - + ) +ENDIF() + IF(ALLOCATOR == "TCMALLOC_256K") SRCS(tcmalloc.cpp) PEERDIR(contrib/libs/tcmalloc) diff --git a/library/cpp/actors/util/funnel_queue.h b/library/cpp/actors/util/funnel_queue.h index d91a8a711b..0e21e2617c 100644 --- a/library/cpp/actors/util/funnel_queue.h +++ b/library/cpp/actors/util/funnel_queue.h @@ -22,7 +22,7 @@ public: Push(ElementType&& element) noexcept { TEntry* const next = NewEntry(static_cast<ElementType&&>(element)); TEntry* const prev = AtomicSwap(&Back, next); - AtomicSet(prev ? prev->Next : Front, next); + AtomicSet(prev ? prev->Next : Front, next); return !prev; } @@ -52,7 +52,7 @@ public: /// Peek top element. Must be used only from one thread. ElementType& Top() const noexcept { - return AtomicGet(Front)->Data; + return AtomicGet(Front)->Data; } bool @@ -191,8 +191,8 @@ private: protected: virtual typename TBase::TEntry* NewEntry(ElementType&& element) noexcept override { - while (const auto top = AtomicGet(Stack)) - if (AtomicCas(&Stack, top->Next, top)) { + while (const auto top = AtomicGet(Stack)) + if (AtomicCas(&Stack, top->Next, top)) { top->Data = static_cast<ElementType&&>(element); AtomicSet(top->Next, nullptr); return top; @@ -206,7 +206,7 @@ protected: const auto next = entry->Next; do AtomicSet(entry->Next, AtomicGet(Stack)); - while (!AtomicCas(&Stack, entry, entry->Next)); + while (!AtomicCas(&Stack, entry, entry->Next)); return next; } }; diff --git a/library/cpp/actors/wilson/wilson_event.h b/library/cpp/actors/wilson/wilson_event.h index 527710da13..7d89c33b51 100644 --- a/library/cpp/actors/wilson/wilson_event.h +++ b/library/cpp/actors/wilson/wilson_event.h @@ -114,7 +114,7 @@ namespace NWilson { // generate wilson event having parent TRACE_ID and span TRACE_ID to become parent of logged event #define WILSON_TRACE(CTX, TRACE_ID, EVENT_NAME, ...) \ - if (::NWilson::TraceEnabled(CTX)) { \ + if (::NWilson::TraceEnabled(CTX)) { \ ::NWilson::TTraceId* __traceId = (TRACE_ID); \ if (__traceId && *__traceId) { \ TInstant now = Now(); \ @@ -123,7 +123,7 @@ namespace NWilson { __UNROLL_PARAMS(__FILL_PARAM, ##__VA_ARGS__) \ ::NWilson::TraceEvent((CTX), __traceId, event, now); \ } \ - } + } inline ui32 GetNodeId(const NActors::TActorSystem& actorSystem) { return actorSystem.NodeId; @@ -133,13 +133,13 @@ namespace NWilson { } constexpr ui32 WilsonComponentId = 430; // kikimrservices: wilson - - template <typename TActorSystem> - bool TraceEnabled(const TActorSystem& ctx) { - const auto* loggerSettings = ctx.LoggerSettings(); + + template <typename TActorSystem> + bool TraceEnabled(const TActorSystem& ctx) { + const auto* loggerSettings = ctx.LoggerSettings(); return loggerSettings && loggerSettings->Satisfies(NActors::NLog::PRI_DEBUG, WilsonComponentId); - } - + } + template <typename TActorSystem, typename TEvent> void TraceEvent(const TActorSystem& actorSystem, TTraceId* traceId, TEvent&& event, TInstant timestamp) { // ensure that we are not using obsolete TraceId diff --git a/library/cpp/cache/cache.h b/library/cpp/cache/cache.h index 93c24f691d..6dc997076d 100644 --- a/library/cpp/cache/cache.h +++ b/library/cpp/cache/cache.h @@ -124,94 +124,94 @@ private: size_t MaxSize; }; -template <typename TKey, typename TValue> -class TLFUList { -public: - TLFUList(size_t maxSize) - : List() - , ListSize(0) - , MaxSize(maxSize) - { - } - +template <typename TKey, typename TValue> +class TLFUList { +public: + TLFUList(size_t maxSize) + : List() + , ListSize(0) + , MaxSize(maxSize) + { + } + struct TItem: public TIntrusiveListItem<TItem> { - typedef TIntrusiveListItem<TItem> TBase; - TItem(const TKey& key, const TValue& value = TValue()) - : TBase() - , Key(key) - , Value(value) - , Counter(0) - { - } - - TItem(const TItem& rhs) - : TBase() - , Key(rhs.Key) - , Value(rhs.Value) - , Counter(rhs.Counter) - { - } - + typedef TIntrusiveListItem<TItem> TBase; + TItem(const TKey& key, const TValue& value = TValue()) + : TBase() + , Key(key) + , Value(value) + , Counter(0) + { + } + + TItem(const TItem& rhs) + : TBase() + , Key(rhs.Key) + , Value(rhs.Value) + , Counter(rhs.Counter) + { + } + bool operator<(const TItem& rhs) const { - return Key < rhs.Key; - } - + return Key < rhs.Key; + } + bool operator==(const TItem& rhs) const { - return Key == rhs.Key; - } - - TKey Key; - TValue Value; - size_t Counter; - - struct THash { + return Key == rhs.Key; + } + + TKey Key; + TValue Value; + size_t Counter; + + struct THash { size_t operator()(const TItem& item) const { - return ::THash<TKey>()(item.Key); - } - }; - }; - -public: - TItem* Insert(TItem* item) { - List.PushBack(item); // give a chance for promotion - ++ListSize; + return ::THash<TKey>()(item.Key); + } + }; + }; + +public: + TItem* Insert(TItem* item) { + List.PushBack(item); // give a chance for promotion + ++ListSize; return RemoveIfOverflown(); } TItem* RemoveIfOverflown() { TItem* deleted = nullptr; - if (ListSize > MaxSize) { - deleted = GetLeastFrequentlyUsed(); - Erase(deleted); - } - return deleted; - } - - TItem* GetLeastFrequentlyUsed() { + if (ListSize > MaxSize) { + deleted = GetLeastFrequentlyUsed(); + Erase(deleted); + } + return deleted; + } + + TItem* GetLeastFrequentlyUsed() { typename TListType::TIterator it = List.Begin(); Y_ASSERT(it != List.End()); - return &*it; - } - - void Erase(TItem* item) { - item->Unlink(); - --ListSize; - } - - void Promote(TItem* item) { - size_t counter = ++item->Counter; + return &*it; + } + + void Erase(TItem* item) { + item->Unlink(); + --ListSize; + } + + void Promote(TItem* item) { + size_t counter = ++item->Counter; typename TListType::TIterator it = item; - while (it != List.End() && counter >= it->Counter) { - ++it; - } - item->LinkBefore(&*it); - } - - size_t GetSize() const { - return ListSize; - } - + while (it != List.End() && counter >= it->Counter) { + ++it; + } + item->LinkBefore(&*it); + } + + size_t GetSize() const { + return ListSize; + } + size_t GetMaxSize() const { return MaxSize; } @@ -222,13 +222,13 @@ public: MaxSize = newSize; } -private: +private: typedef TIntrusiveList<TItem> TListType; TListType List; - size_t ListSize; - size_t MaxSize; -}; - + size_t ListSize; + size_t MaxSize; +}; + // Least Weighted list // discards the least weighted items first // doesn't support promotion @@ -578,7 +578,7 @@ template <typename TKey, typename TValue, typename TDeleter = TNoopDelete, class class TLRUCache: public TCache<TKey, TValue, TLRUList<TKey, TValue, TSizeProvider>, TDeleter> { using TListType = TLRUList<TKey, TValue, TSizeProvider>; typedef TCache<TKey, TValue, TListType, TDeleter> TBase; - + public: TLRUCache(size_t maxSize, bool multiValue = false, const TSizeProvider& sizeProvider = TSizeProvider()) : TBase(TListType(maxSize, sizeProvider), multiValue) @@ -600,28 +600,28 @@ public: return TBase::List.GetTotalSize(); } }; - -template <typename TKey, typename TValue, typename TDeleter = TNoopDelete> + +template <typename TKey, typename TValue, typename TDeleter = TNoopDelete> class TLFUCache: public TCache<TKey, TValue, TLFUList<TKey, TValue>, TDeleter> { typedef TCache<TKey, TValue, TLFUList<TKey, TValue>, TDeleter> TBase; using TListType = TLFUList<TKey, TValue>; - -public: - typedef typename TBase::TIterator TIterator; - - TLFUCache(size_t maxSize, bool multiValue = false) + +public: + typedef typename TBase::TIterator TIterator; + + TLFUCache(size_t maxSize, bool multiValue = false) : TBase(TListType(maxSize), multiValue) - { - } - - TValue& GetLeastFrequentlyUsed() { - return TBase::List.GetLeastFrequentlyUsed()->Value; - } - - TIterator FindLeastFrequentlyUsed() { - return TBase::Empty() ? TBase::End() : this->FindByItem(TBase::List.GetLeastFrequentlyUsed()); - } -}; + { + } + + TValue& GetLeastFrequentlyUsed() { + return TBase::List.GetLeastFrequentlyUsed()->Value; + } + + TIterator FindLeastFrequentlyUsed() { + return TBase::Empty() ? TBase::End() : this->FindByItem(TBase::List.GetLeastFrequentlyUsed()); + } +}; // Least Weighted cache // discards the least weighted items first diff --git a/library/cpp/cache/ut/cache_ut.cpp b/library/cpp/cache/ut/cache_ut.cpp index 96fabc10d7..329872cfde 100644 --- a/library/cpp/cache/ut/cache_ut.cpp +++ b/library/cpp/cache/ut/cache_ut.cpp @@ -12,23 +12,23 @@ Y_UNIT_TEST_SUITE(TCacheTest) { Y_UNIT_TEST(LRUListTest) { typedef TLRUList<int, TString> TListType; TListType list(2); - + TListType::TItem x1(1, "ttt"); list.Insert(&x1); UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); - + TListType::TItem x2(2, "yyy"); list.Insert(&x2); UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); - + list.Promote(list.GetOldest()); UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 2); - + TListType::TItem x3(3, "zzz"); list.Insert(&x3); UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); - } - + } + Y_UNIT_TEST(LRUListWeightedTest) { typedef TLRUList<int, TString, size_t (*)(const TString&)> TListType; TListType list(7, [](auto& string) { @@ -68,23 +68,23 @@ Y_UNIT_TEST_SUITE(TCacheTest) { Y_UNIT_TEST(LFUListTest) { typedef TLFUList<int, TString> TListType; TListType list(2); - + TListType::TItem x1(1, "ttt"); list.Insert(&x1); UNIT_ASSERT_EQUAL(list.GetLeastFrequentlyUsed()->Key, 1); - + TListType::TItem x2(2, "yyy"); list.Insert(&x2); UNIT_ASSERT_EQUAL(list.GetLeastFrequentlyUsed()->Key, 1); - + list.Promote(list.GetLeastFrequentlyUsed()); UNIT_ASSERT_EQUAL(list.GetLeastFrequentlyUsed()->Key, 2); - + TListType::TItem x3(3, "zzz"); list.Insert(&x3); UNIT_ASSERT_EQUAL(list.GetLeastFrequentlyUsed()->Key, 1); - } - + } + Y_UNIT_TEST(LWListTest) { typedef TLWList<int, TString, size_t, TStrokaWeighter> TListType; TListType list(2); diff --git a/library/cpp/containers/paged_vector/ya.make b/library/cpp/containers/paged_vector/ya.make index ebb5349c27..e14548bc2c 100644 --- a/library/cpp/containers/paged_vector/ya.make +++ b/library/cpp/containers/paged_vector/ya.make @@ -1,9 +1,9 @@ -LIBRARY() - -OWNER(velavokr) - -SRCS( - paged_vector.cpp -) - -END() +LIBRARY() + +OWNER(velavokr) + +SRCS( + paged_vector.cpp +) + +END() diff --git a/library/cpp/containers/stack_vector/stack_vec.h b/library/cpp/containers/stack_vector/stack_vec.h index 6fe57e2e91..fcc5d9a2a5 100644 --- a/library/cpp/containers/stack_vector/stack_vec.h +++ b/library/cpp/containers/stack_vector/stack_vec.h @@ -135,21 +135,21 @@ public: { } - template <class A> + template <class A> TStackVec(const TVector<T, A>& src) : TStackVec(src.begin(), src.end()) - { - } - + { + } + TStackVec(std::initializer_list<T> il, const TAllocator& alloc = TAllocator()) : TStackVec(il.begin(), il.end(), alloc) - { - } - - template <class TIter> + { + } + + template <class TIter> TStackVec(TIter first, TIter last, const TAllocator& alloc = TAllocator()) : TBase(alloc) - { + { // NB(eeight) Since we want to call 'reserve' here, we cannot just delegate to TVector ctor. // The best way to insert values afterwards is to call TVector::insert. However there is a caveat. // In order to call this ctor of TVector, T needs to be just move-constructible. Insert however @@ -164,27 +164,27 @@ public: TBase::push_back(*first); } } - } - + } + public: void swap(TStackVec&) = delete; void shrink_to_fit() = delete; TStackVec& operator=(const TStackVec& src) { - TBase::assign(src.begin(), src.end()); + TBase::assign(src.begin(), src.end()); return *this; } - - template <class A> + + template <class A> TStackVec& operator=(const TVector<T, A>& src) { - TBase::assign(src.begin(), src.end()); - return *this; - } - + TBase::assign(src.begin(), src.end()); + return *this; + } + TStackVec& operator=(std::initializer_list<T> il) { - TBase::assign(il.begin(), il.end()); - return *this; - } + TBase::assign(il.begin(), il.end()); + return *this; + } }; template <typename T, size_t CountOnStack, class Alloc> diff --git a/library/cpp/lfalloc/alloc_profiler/profiler.cpp b/library/cpp/lfalloc/alloc_profiler/profiler.cpp index 4c081bf64f..0e30927a5a 100644 --- a/library/cpp/lfalloc/alloc_profiler/profiler.cpp +++ b/library/cpp/lfalloc/alloc_profiler/profiler.cpp @@ -1,81 +1,81 @@ -#include "profiler.h" +#include "profiler.h" -#include "stackcollect.h" - -#include <util/generic/algorithm.h> -#include <util/generic/singleton.h> +#include "stackcollect.h" + +#include <util/generic/algorithm.h> +#include <util/generic/singleton.h> #include <util/generic/string.h> -#include <util/generic/vector.h> -#include <util/stream/str.h> - +#include <util/generic/vector.h> +#include <util/stream/str.h> + namespace NAllocProfiler { - -namespace { - -static TAllocationStackCollector& AllocationStackCollector() -{ - return *Singleton<TAllocationStackCollector>(); -} - -int AllocationCallback(int tag, size_t size, int sizeIdx) -{ - Y_UNUSED(sizeIdx); - - static const size_t STACK_FRAMES_COUNT = 32; - static const size_t STACK_FRAMES_SKIP = 1; - - void* frames[STACK_FRAMES_COUNT]; - size_t frameCount = BackTrace(frames, Y_ARRAY_SIZE(frames)); - if (frameCount <= STACK_FRAMES_SKIP) { - return -1; - } - - void** stack = &frames[STACK_FRAMES_SKIP]; - frameCount -= STACK_FRAMES_SKIP; - - auto& collector = AllocationStackCollector(); - return collector.Alloc(stack, frameCount, tag, size); -} - -void DeallocationCallback(int stackId, int tag, size_t size, int sizeIdx) -{ - Y_UNUSED(tag); - Y_UNUSED(sizeIdx); - - auto& collector = AllocationStackCollector(); - collector.Free(stackId, size); -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// - + +namespace { + +static TAllocationStackCollector& AllocationStackCollector() +{ + return *Singleton<TAllocationStackCollector>(); +} + +int AllocationCallback(int tag, size_t size, int sizeIdx) +{ + Y_UNUSED(sizeIdx); + + static const size_t STACK_FRAMES_COUNT = 32; + static const size_t STACK_FRAMES_SKIP = 1; + + void* frames[STACK_FRAMES_COUNT]; + size_t frameCount = BackTrace(frames, Y_ARRAY_SIZE(frames)); + if (frameCount <= STACK_FRAMES_SKIP) { + return -1; + } + + void** stack = &frames[STACK_FRAMES_SKIP]; + frameCount -= STACK_FRAMES_SKIP; + + auto& collector = AllocationStackCollector(); + return collector.Alloc(stack, frameCount, tag, size); +} + +void DeallocationCallback(int stackId, int tag, size_t size, int sizeIdx) +{ + Y_UNUSED(tag); + Y_UNUSED(sizeIdx); + + auto& collector = AllocationStackCollector(); + collector.Free(stackId, size); +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + bool StartAllocationSampling(bool profileAllThreads) -{ - auto& collector = AllocationStackCollector(); - collector.Clear(); - +{ + auto& collector = AllocationStackCollector(); + collector.Clear(); + NAllocDbg::SetProfileAllThreads(profileAllThreads); - NAllocDbg::SetAllocationCallback(AllocationCallback); - NAllocDbg::SetDeallocationCallback(DeallocationCallback); - NAllocDbg::SetAllocationSamplingEnabled(true); - return true; -} - + NAllocDbg::SetAllocationCallback(AllocationCallback); + NAllocDbg::SetDeallocationCallback(DeallocationCallback); + NAllocDbg::SetAllocationSamplingEnabled(true); + return true; +} + bool StopAllocationSampling(IAllocationStatsDumper &out, int count) -{ - NAllocDbg::SetAllocationCallback(nullptr); - NAllocDbg::SetDeallocationCallback(nullptr); - NAllocDbg::SetAllocationSamplingEnabled(false); - - auto& collector = AllocationStackCollector(); +{ + NAllocDbg::SetAllocationCallback(nullptr); + NAllocDbg::SetDeallocationCallback(nullptr); + NAllocDbg::SetAllocationSamplingEnabled(false); + + auto& collector = AllocationStackCollector(); collector.Dump(count, out); - return true; -} - + return true; +} + bool StopAllocationSampling(IOutputStream& out, int count) { TAllocationStatsDumper dumper(out); return StopAllocationSampling(dumper, count); -} - -} // namespace NProfiler +} + +} // namespace NProfiler diff --git a/library/cpp/lfalloc/alloc_profiler/profiler.h b/library/cpp/lfalloc/alloc_profiler/profiler.h index 0cd816fa03..4ea49b9dcc 100644 --- a/library/cpp/lfalloc/alloc_profiler/profiler.h +++ b/library/cpp/lfalloc/alloc_profiler/profiler.h @@ -1,45 +1,45 @@ -#pragma once - +#pragma once + #include "stackcollect.h" - + #include <library/cpp/lfalloc/dbg_info/dbg_info.h> - -#include <util/generic/noncopyable.h> + +#include <util/generic/noncopyable.h> #include <util/stream/output.h> - + namespace NAllocProfiler { - -//////////////////////////////////////////////////////////////////////////////// - -inline int SetCurrentScopeTag(int value) -{ - return NAllocDbg::SetThreadAllocTag(value); -} - -inline bool SetProfileCurrentThread(bool value) -{ - return NAllocDbg::SetProfileCurrentThread(value); -} - + +//////////////////////////////////////////////////////////////////////////////// + +inline int SetCurrentScopeTag(int value) +{ + return NAllocDbg::SetThreadAllocTag(value); +} + +inline bool SetProfileCurrentThread(bool value) +{ + return NAllocDbg::SetProfileCurrentThread(value); +} + bool StartAllocationSampling(bool profileAllThreads = false); bool StopAllocationSampling(IAllocationStatsDumper& out, int count = 100); bool StopAllocationSampling(IOutputStream& out, int count = 100); - -//////////////////////////////////////////////////////////////////////////////// - -class TProfilingScope: private TNonCopyable { -private: - const int Prev; - -public: - explicit TProfilingScope(int value) - : Prev(SetCurrentScopeTag(value)) - {} - - ~TProfilingScope() - { - SetCurrentScopeTag(Prev); - } -}; - + +//////////////////////////////////////////////////////////////////////////////// + +class TProfilingScope: private TNonCopyable { +private: + const int Prev; + +public: + explicit TProfilingScope(int value) + : Prev(SetCurrentScopeTag(value)) + {} + + ~TProfilingScope() + { + SetCurrentScopeTag(Prev); + } +}; + } // namespace NAllocProfiler diff --git a/library/cpp/lfalloc/alloc_profiler/stackcollect.cpp b/library/cpp/lfalloc/alloc_profiler/stackcollect.cpp index 5a0c920451..fded4e2fd1 100644 --- a/library/cpp/lfalloc/alloc_profiler/stackcollect.cpp +++ b/library/cpp/lfalloc/alloc_profiler/stackcollect.cpp @@ -1,278 +1,278 @@ -#include "stackcollect.h" +#include "stackcollect.h" -#include "profiler.h" - -#include <util/generic/algorithm.h> -#include <util/generic/vector.h> -#include <util/stream/format.h> +#include "profiler.h" + +#include <util/generic/algorithm.h> +#include <util/generic/vector.h> +#include <util/stream/format.h> #include <util/stream/str.h> #include <util/string/cast.h> #include <util/string/printf.h> -#include <util/system/backtrace.h> -#include <util/system/spinlock.h> -#include <util/system/yassert.h> - - +#include <util/system/backtrace.h> +#include <util/system/spinlock.h> +#include <util/system/yassert.h> + + namespace NAllocProfiler { -//////////////////////////////////////////////////////////////////////////////// - -template <typename T> -class TStackCollector: private TNonCopyable { -public: - struct TFrameInfo { - int PrevInd; - void* Addr; - int Tag; - T Stats; - - void Clear() - { - PrevInd = 0; - Addr = nullptr; - Tag = 0; - Stats.Clear(); - } - }; - -private: - static const size_t STACKS_HASH_MAP_SIZE = 256 * 1024; - TFrameInfo Frames[STACKS_HASH_MAP_SIZE]; - - ui64 Samples; // Saved samples count - ui64 UniqueSamples; // Number of unique addresses - ui64 UsedSlots; // Number of occupied slots in the hashtable - ui64 DroppedSamples; // Number of unsaved addresses - ui64 SearchSkipCount; // Total number of linear hash table probes due to collisions - - TAdaptiveLock Lock; - -public: - TStackCollector() - { - Clear(); - } - - int AddStack(void** stack, size_t frameCount, int tag) - { - Y_ASSERT(frameCount > 0); - - int prevInd = -1; - with_lock (Lock) { - for (int i = frameCount - 1; i >= 0; --i) { - prevInd = AddFrame(stack[i], prevInd, ((i == 0) ? tag : 0), (i == 0)); - if (prevInd == -1) { - break; - } - } - } - return prevInd; - } - - T& GetStats(int stackId) - { - Y_ASSERT(stackId >= 0 && (size_t)stackId < Y_ARRAY_SIZE(Frames)); - Y_ASSERT(!IsSlotEmpty(stackId)); - - return Frames[stackId].Stats; - } - - const TFrameInfo* GetFrames() const - { - return Frames; - } - - size_t GetFramesCount() const - { - return Y_ARRAY_SIZE(Frames); - } - +//////////////////////////////////////////////////////////////////////////////// + +template <typename T> +class TStackCollector: private TNonCopyable { +public: + struct TFrameInfo { + int PrevInd; + void* Addr; + int Tag; + T Stats; + + void Clear() + { + PrevInd = 0; + Addr = nullptr; + Tag = 0; + Stats.Clear(); + } + }; + +private: + static const size_t STACKS_HASH_MAP_SIZE = 256 * 1024; + TFrameInfo Frames[STACKS_HASH_MAP_SIZE]; + + ui64 Samples; // Saved samples count + ui64 UniqueSamples; // Number of unique addresses + ui64 UsedSlots; // Number of occupied slots in the hashtable + ui64 DroppedSamples; // Number of unsaved addresses + ui64 SearchSkipCount; // Total number of linear hash table probes due to collisions + + TAdaptiveLock Lock; + +public: + TStackCollector() + { + Clear(); + } + + int AddStack(void** stack, size_t frameCount, int tag) + { + Y_ASSERT(frameCount > 0); + + int prevInd = -1; + with_lock (Lock) { + for (int i = frameCount - 1; i >= 0; --i) { + prevInd = AddFrame(stack[i], prevInd, ((i == 0) ? tag : 0), (i == 0)); + if (prevInd == -1) { + break; + } + } + } + return prevInd; + } + + T& GetStats(int stackId) + { + Y_ASSERT(stackId >= 0 && (size_t)stackId < Y_ARRAY_SIZE(Frames)); + Y_ASSERT(!IsSlotEmpty(stackId)); + + return Frames[stackId].Stats; + } + + const TFrameInfo* GetFrames() const + { + return Frames; + } + + size_t GetFramesCount() const + { + return Y_ARRAY_SIZE(Frames); + } + void BackTrace(const TFrameInfo* stack, TStackVec<void*, 64>& frames) const - { + { frames.clear(); - for (size_t i = 0; i < 100; ++i) { + for (size_t i = 0; i < 100; ++i) { frames.push_back(stack->Addr); - int prevInd = stack->PrevInd; - if (prevInd == -1) { - break; - } - stack = &Frames[prevInd]; - } - } - - void Clear() - { - for (auto& frame: Frames) { - frame.Clear(); - } - - Samples = 0; - DroppedSamples = 0; - UniqueSamples = 0; - UsedSlots = 0; - SearchSkipCount = 0; - } - -private: - // Hash function applied to the addresses - static ui32 Hash(void* addr, int prevInd, int tag) - { - return (((size_t)addr + ((size_t)addr / STACKS_HASH_MAP_SIZE)) + prevInd + tag) % STACKS_HASH_MAP_SIZE; - } - - static bool EqualFrame(const TFrameInfo& frame, void* addr, int prevInd, int tag) - { - return (frame.Addr == addr && frame.PrevInd == prevInd && frame.Tag == tag); - } - - bool IsSlotEmpty(ui32 slot) const - { - return Frames[slot].Addr == 0; - } - - bool InsertsAllowed() const - { - return UsedSlots < STACKS_HASH_MAP_SIZE / 2; - } - - // returns the index in the hashmap - int AddFrame(void* addr, int prevFrameIndex, int tag, bool last) - { - ui32 slot = Hash(addr, prevFrameIndex, tag); - ui32 prevSlot = (slot - 1) % STACKS_HASH_MAP_SIZE; - - while (!EqualFrame(Frames[slot], addr, prevFrameIndex, tag) && !IsSlotEmpty(slot) && slot != prevSlot) { - slot = (slot + 1) % STACKS_HASH_MAP_SIZE; - SearchSkipCount++; - } - - if (EqualFrame(Frames[slot], addr, prevFrameIndex, tag)) { - if (last) { - ++Samples; - } - } else if (InsertsAllowed() && IsSlotEmpty(slot)) { - // add new sample - Frames[slot].Clear(); - Frames[slot].Addr = addr; - Frames[slot].PrevInd = prevFrameIndex; - Frames[slot].Tag = tag; - ++UsedSlots; - if (last) { - ++UniqueSamples; - ++Samples; - } - } else { - // don't insert new sample if the search is becoming too slow - ++DroppedSamples; - return -1; - } - - return slot; - } -}; - - -//////////////////////////////////////////////////////////////////////////////// - + int prevInd = stack->PrevInd; + if (prevInd == -1) { + break; + } + stack = &Frames[prevInd]; + } + } + + void Clear() + { + for (auto& frame: Frames) { + frame.Clear(); + } + + Samples = 0; + DroppedSamples = 0; + UniqueSamples = 0; + UsedSlots = 0; + SearchSkipCount = 0; + } + +private: + // Hash function applied to the addresses + static ui32 Hash(void* addr, int prevInd, int tag) + { + return (((size_t)addr + ((size_t)addr / STACKS_HASH_MAP_SIZE)) + prevInd + tag) % STACKS_HASH_MAP_SIZE; + } + + static bool EqualFrame(const TFrameInfo& frame, void* addr, int prevInd, int tag) + { + return (frame.Addr == addr && frame.PrevInd == prevInd && frame.Tag == tag); + } + + bool IsSlotEmpty(ui32 slot) const + { + return Frames[slot].Addr == 0; + } + + bool InsertsAllowed() const + { + return UsedSlots < STACKS_HASH_MAP_SIZE / 2; + } + + // returns the index in the hashmap + int AddFrame(void* addr, int prevFrameIndex, int tag, bool last) + { + ui32 slot = Hash(addr, prevFrameIndex, tag); + ui32 prevSlot = (slot - 1) % STACKS_HASH_MAP_SIZE; + + while (!EqualFrame(Frames[slot], addr, prevFrameIndex, tag) && !IsSlotEmpty(slot) && slot != prevSlot) { + slot = (slot + 1) % STACKS_HASH_MAP_SIZE; + SearchSkipCount++; + } + + if (EqualFrame(Frames[slot], addr, prevFrameIndex, tag)) { + if (last) { + ++Samples; + } + } else if (InsertsAllowed() && IsSlotEmpty(slot)) { + // add new sample + Frames[slot].Clear(); + Frames[slot].Addr = addr; + Frames[slot].PrevInd = prevFrameIndex; + Frames[slot].Tag = tag; + ++UsedSlots; + if (last) { + ++UniqueSamples; + ++Samples; + } + } else { + // don't insert new sample if the search is becoming too slow + ++DroppedSamples; + return -1; + } + + return slot; + } +}; + + +//////////////////////////////////////////////////////////////////////////////// + class TAllocationStackCollector::TImpl: public TStackCollector<TStats> { using TBase = TStackCollector<TStats>; - -private: + +private: TStats Total; - -public: - int Alloc(void** stack, size_t frameCount, int tag, size_t size) - { - int stackId = TBase::AddStack(stack, frameCount, tag); - if (stackId >= 0) { - TBase::GetStats(stackId).Alloc(size); - Total.Alloc(size); - } - return stackId; - } - - void Free(int stackId, size_t size) - { - TBase::GetStats(stackId).Free(size); - Total.Free(size); - } - - void Clear() - { - TBase::Clear(); - Total.Clear(); - } - + +public: + int Alloc(void** stack, size_t frameCount, int tag, size_t size) + { + int stackId = TBase::AddStack(stack, frameCount, tag); + if (stackId >= 0) { + TBase::GetStats(stackId).Alloc(size); + Total.Alloc(size); + } + return stackId; + } + + void Free(int stackId, size_t size) + { + TBase::GetStats(stackId).Free(size); + Total.Free(size); + } + + void Clear() + { + TBase::Clear(); + Total.Clear(); + } + void Dump(int count, IAllocationStatsDumper& out) const - { - const TFrameInfo* frames = TBase::GetFrames(); - size_t framesCount = TBase::GetFramesCount(); - + { + const TFrameInfo* frames = TBase::GetFrames(); + size_t framesCount = TBase::GetFramesCount(); + TVector<const TFrameInfo*> stacks; - for (size_t i = 0; i < framesCount; ++i) { - if (frames[i].Stats.Allocs) { - stacks.push_back(&frames[i]); - } - } - - Sort(stacks, [] (const TFrameInfo* l, const TFrameInfo* r) { - const auto& ls = l->Stats; - const auto& rs = r->Stats; - return ls.CurrentSize != rs.CurrentSize - ? ls.CurrentSize > rs.CurrentSize - : ls.Allocs != rs.Allocs - ? ls.Allocs > rs.Allocs - : ls.Frees > rs.Frees; - }); - + for (size_t i = 0; i < framesCount; ++i) { + if (frames[i].Stats.Allocs) { + stacks.push_back(&frames[i]); + } + } + + Sort(stacks, [] (const TFrameInfo* l, const TFrameInfo* r) { + const auto& ls = l->Stats; + const auto& rs = r->Stats; + return ls.CurrentSize != rs.CurrentSize + ? ls.CurrentSize > rs.CurrentSize + : ls.Allocs != rs.Allocs + ? ls.Allocs > rs.Allocs + : ls.Frees > rs.Frees; + }); + out.DumpTotal(Total); - + TAllocationInfo allocInfo; - int printedCount = 0; - for (const TFrameInfo* stack: stacks) { + int printedCount = 0; + for (const TFrameInfo* stack: stacks) { allocInfo.Clear(); allocInfo.Tag = stack->Tag; allocInfo.Stats = stack->Stats; TBase::BackTrace(stack, allocInfo.Stack); - + out.DumpEntry(allocInfo); - if (++printedCount >= count) { - break; - } - } - } -}; - -//////////////////////////////////////////////////////////////////////////////// - -TAllocationStackCollector::TAllocationStackCollector() - : Impl(new TImpl()) -{} - -TAllocationStackCollector::~TAllocationStackCollector() -{} - -int TAllocationStackCollector::Alloc(void** stack, size_t frameCount, int tag, size_t size) -{ - return Impl->Alloc(stack, frameCount, tag, size); -} - -void TAllocationStackCollector::Free(int stackId, size_t size) -{ - Impl->Free(stackId, size); -} - -void TAllocationStackCollector::Clear() -{ - Impl->Clear(); -} - + if (++printedCount >= count) { + break; + } + } + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +TAllocationStackCollector::TAllocationStackCollector() + : Impl(new TImpl()) +{} + +TAllocationStackCollector::~TAllocationStackCollector() +{} + +int TAllocationStackCollector::Alloc(void** stack, size_t frameCount, int tag, size_t size) +{ + return Impl->Alloc(stack, frameCount, tag, size); +} + +void TAllocationStackCollector::Free(int stackId, size_t size) +{ + Impl->Free(stackId, size); +} + +void TAllocationStackCollector::Clear() +{ + Impl->Clear(); +} + void TAllocationStackCollector::Dump(int count, IAllocationStatsDumper &out) const -{ - Impl->Dump(count, out); -} - +{ + Impl->Dump(count, out); +} + TString IAllocationStatsDumper::FormatTag(int tag) { return ToString(tag); diff --git a/library/cpp/lfalloc/alloc_profiler/stackcollect.h b/library/cpp/lfalloc/alloc_profiler/stackcollect.h index 8c0d65b296..80715ed7cb 100644 --- a/library/cpp/lfalloc/alloc_profiler/stackcollect.h +++ b/library/cpp/lfalloc/alloc_profiler/stackcollect.h @@ -1,14 +1,14 @@ -#pragma once - +#pragma once + #include <library/cpp/containers/stack_vector/stack_vec.h> #include <library/cpp/cache/cache.h> -#include <util/generic/noncopyable.h> -#include <util/generic/ptr.h> +#include <util/generic/noncopyable.h> +#include <util/generic/ptr.h> #include <util/stream/output.h> - + namespace NAllocProfiler { - + struct TStats { intptr_t Allocs = 0; intptr_t Frees = 0; @@ -85,23 +85,23 @@ private: TLFUCache<void*, TSymbol> SymbolCache; }; -//////////////////////////////////////////////////////////////////////////////// - -class TAllocationStackCollector: private TNonCopyable { -private: - class TImpl; - THolder<TImpl> Impl; - -public: - TAllocationStackCollector(); - ~TAllocationStackCollector(); - - int Alloc(void** stack, size_t frameCount, int tag, size_t size); - void Free(int stackId, size_t size); - - void Clear(); - +//////////////////////////////////////////////////////////////////////////////// + +class TAllocationStackCollector: private TNonCopyable { +private: + class TImpl; + THolder<TImpl> Impl; + +public: + TAllocationStackCollector(); + ~TAllocationStackCollector(); + + int Alloc(void** stack, size_t frameCount, int tag, size_t size); + void Free(int stackId, size_t size); + + void Clear(); + void Dump(int count, IAllocationStatsDumper& out) const; -}; - +}; + } // namespace NAllocProfiler diff --git a/library/cpp/lfalloc/dbg/ya.make b/library/cpp/lfalloc/dbg/ya.make index 387050fc67..3dce653a8c 100644 --- a/library/cpp/lfalloc/dbg/ya.make +++ b/library/cpp/lfalloc/dbg/ya.make @@ -1,32 +1,32 @@ -LIBRARY() +LIBRARY() -OWNER(vskipin) - -NO_UTIL() +OWNER(vskipin) -NO_COMPILER_WARNINGS() - -IF (ARCH_AARCH64) - PEERDIR( - contrib/libs/jemalloc - ) -ELSE() - IF ("${YMAKE}" MATCHES "devtools") - CFLAGS(-DYMAKE=1) - ENDIF() +NO_UTIL() + +NO_COMPILER_WARNINGS() + +IF (ARCH_AARCH64) + PEERDIR( + contrib/libs/jemalloc + ) +ELSE() + IF ("${YMAKE}" MATCHES "devtools") + CFLAGS(-DYMAKE=1) + ENDIF() CXXFLAGS( -DLFALLOC_DBG -DLFALLOC_YT ) - SRCS( - ../lf_allocX64.cpp - ) -ENDIF() - -PEERDIR( + SRCS( + ../lf_allocX64.cpp + ) +ENDIF() + +PEERDIR( library/cpp/malloc/api -) - -SET(IDE_FOLDER "util") - -END() +) + +SET(IDE_FOLDER "util") + +END() diff --git a/library/cpp/lfalloc/dbg_info/dbg_info.cpp b/library/cpp/lfalloc/dbg_info/dbg_info.cpp index c900cb4f96..1fb9f7ad93 100644 --- a/library/cpp/lfalloc/dbg_info/dbg_info.cpp +++ b/library/cpp/lfalloc/dbg_info/dbg_info.cpp @@ -1,83 +1,83 @@ -#include "dbg_info.h" - +#include "dbg_info.h" + #include <library/cpp/malloc/api/malloc.h> - -namespace NAllocDbg { + +namespace NAllocDbg { //////////////////////////////////////////////////////////////////////////////// - + using TGetAllocationCounter = i64(int counter); - + using TSetThreadAllocTag = int(int tag); using TGetPerTagAllocInfo = void( bool flushPerThreadCounters, TPerTagAllocInfo* info, int& maxTag, int& numSizes); - + using TSetProfileCurrentThread = bool(bool newVal); using TSetProfileAllThreads = bool(bool newVal); using TSetAllocationSamplingEnabled = bool(bool newVal); - + using TSetAllocationSampleRate = size_t(size_t newVal); using TSetAllocationSampleMaxSize = size_t(size_t newVal); - + using TSetAllocationCallback = TAllocationCallback*(TAllocationCallback* newVal); using TSetDeallocationCallback = TDeallocationCallback*(TDeallocationCallback* newVal); - + struct TAllocFn { TGetAllocationCounter* GetAllocationCounterFast = nullptr; TGetAllocationCounter* GetAllocationCounterFull = nullptr; - + TSetThreadAllocTag* SetThreadAllocTag = nullptr; TGetPerTagAllocInfo* GetPerTagAllocInfo = nullptr; - + TSetProfileCurrentThread* SetProfileCurrentThread = nullptr; TSetProfileAllThreads* SetProfileAllThreads = nullptr; TSetAllocationSamplingEnabled* SetAllocationSamplingEnabled = nullptr; - + TSetAllocationSampleRate* SetAllocationSampleRate = nullptr; TSetAllocationSampleMaxSize* SetAllocationSampleMaxSize = nullptr; - + TSetAllocationCallback* SetAllocationCallback = nullptr; TSetDeallocationCallback* SetDeallocationCallback = nullptr; - + TAllocFn() { auto mallocInfo = NMalloc::MallocInfo(); - + GetAllocationCounterFast = (TGetAllocationCounter*)mallocInfo.GetParam("GetLFAllocCounterFast"); GetAllocationCounterFull = (TGetAllocationCounter*)mallocInfo.GetParam("GetLFAllocCounterFull"); - + SetThreadAllocTag = (TSetThreadAllocTag*)mallocInfo.GetParam("SetThreadAllocTag"); GetPerTagAllocInfo = (TGetPerTagAllocInfo*)mallocInfo.GetParam("GetPerTagAllocInfo"); - + SetProfileCurrentThread = (TSetProfileCurrentThread*)mallocInfo.GetParam("SetProfileCurrentThread"); SetProfileAllThreads = (TSetProfileAllThreads*)mallocInfo.GetParam("SetProfileAllThreads"); SetAllocationSamplingEnabled = (TSetAllocationSamplingEnabled*)mallocInfo.GetParam("SetAllocationSamplingEnabled"); - + SetAllocationSampleRate = (TSetAllocationSampleRate*)mallocInfo.GetParam("SetAllocationSampleRate"); SetAllocationSampleMaxSize = (TSetAllocationSampleMaxSize*)mallocInfo.GetParam("SetAllocationSampleMaxSize"); - + SetAllocationCallback = (TSetAllocationCallback*)mallocInfo.GetParam("SetAllocationCallback"); SetDeallocationCallback = (TSetDeallocationCallback*)mallocInfo.GetParam("SetDeallocationCallback"); } }; - + //////////////////////////////////////////////////////////////////////////////// - + static TAllocFn AllocFn; - + i64 GetAllocationCounterFast(ELFAllocCounter counter) { return AllocFn.GetAllocationCounterFast ? AllocFn.GetAllocationCounterFast(counter) : 0; } - + i64 GetAllocationCounterFull(ELFAllocCounter counter) { return AllocFn.GetAllocationCounterFull ? AllocFn.GetAllocationCounterFull(counter) : 0; } - + int SetThreadAllocTag(int tag) { return AllocFn.SetThreadAllocTag ? AllocFn.SetThreadAllocTag(tag) : 0; } - + TArrayPtr<TPerTagAllocInfo> GetPerTagAllocInfo( bool flushPerThreadCounters, int& maxTag, @@ -92,11 +92,11 @@ namespace NAllocDbg { numSizes = 0; return nullptr; } - + bool SetProfileCurrentThread(bool newVal) { return AllocFn.SetProfileCurrentThread ? AllocFn.SetProfileCurrentThread(newVal) : false; - } - + } + bool SetProfileAllThreads(bool newVal) { return AllocFn.SetProfileAllThreads ? AllocFn.SetProfileAllThreads(newVal) : false; } @@ -104,21 +104,21 @@ namespace NAllocDbg { bool SetAllocationSamplingEnabled(bool newVal) { return AllocFn.SetAllocationSamplingEnabled ? AllocFn.SetAllocationSamplingEnabled(newVal) : false; } - + size_t SetAllocationSampleRate(size_t newVal) { return AllocFn.SetAllocationSampleRate ? AllocFn.SetAllocationSampleRate(newVal) : 0; } - + size_t SetAllocationSampleMaxSize(size_t newVal) { return AllocFn.SetAllocationSampleMaxSize ? AllocFn.SetAllocationSampleMaxSize(newVal) : 0; } - + TAllocationCallback* SetAllocationCallback(TAllocationCallback* newVal) { return AllocFn.SetAllocationCallback ? AllocFn.SetAllocationCallback(newVal) : nullptr; } - + TDeallocationCallback* SetDeallocationCallback(TDeallocationCallback* newVal) { return AllocFn.SetDeallocationCallback ? AllocFn.SetDeallocationCallback(newVal) : nullptr; } - -} + +} diff --git a/library/cpp/lfalloc/dbg_info/dbg_info.h b/library/cpp/lfalloc/dbg_info/dbg_info.h index 0c3299216d..071562a81a 100644 --- a/library/cpp/lfalloc/dbg_info/dbg_info.h +++ b/library/cpp/lfalloc/dbg_info/dbg_info.h @@ -1,12 +1,12 @@ -#pragma once - +#pragma once + #include <util/generic/ptr.h> -#include <util/system/types.h> - -namespace NAllocDbg { +#include <util/system/types.h> + +namespace NAllocDbg { //////////////////////////////////////////////////////////////////////////////// // Allocation statistics - + enum ELFAllocCounter { CT_USER_ALLOC, // accumulated size requested by user code CT_MMAP, // accumulated mmapped size @@ -23,55 +23,55 @@ namespace NAllocDbg { CT_DEGRAGMENT_CNT, // number of memory defragmentations CT_MAX }; - + i64 GetAllocationCounterFast(ELFAllocCounter counter); i64 GetAllocationCounterFull(ELFAllocCounter counter); - + //////////////////////////////////////////////////////////////////////////////// // Allocation statistics could be tracked on per-tag basis - + int SetThreadAllocTag(int tag); - + class TScopedTag { private: int PrevTag; - + public: explicit TScopedTag(int tag) { PrevTag = SetThreadAllocTag(tag); } - + ~TScopedTag() { SetThreadAllocTag(PrevTag); } }; - + struct TPerTagAllocInfo { ssize_t Count; ssize_t Size; }; - + TArrayPtr<TPerTagAllocInfo> GetPerTagAllocInfo( bool flushPerThreadCounters, int& maxTag, int& numSizes); - + //////////////////////////////////////////////////////////////////////////////// // Allocation sampling could be used to collect detailed information - + bool SetProfileCurrentThread(bool newVal); bool SetProfileAllThreads(bool newVal); bool SetAllocationSamplingEnabled(bool newVal); - + size_t SetAllocationSampleRate(size_t newVal); size_t SetAllocationSampleMaxSize(size_t newVal); - -#define DBG_ALLOC_INVALID_COOKIE (-1) - + +#define DBG_ALLOC_INVALID_COOKIE (-1) + using TAllocationCallback = int(int tag, size_t size, int sizeIdx); using TDeallocationCallback = void(int cookie, int tag, size_t size, int sizeIdx); - + TAllocationCallback* SetAllocationCallback(TAllocationCallback* newVal); TDeallocationCallback* SetDeallocationCallback(TDeallocationCallback* newVal); - + } diff --git a/library/cpp/lfalloc/dbg_info/ya.make b/library/cpp/lfalloc/dbg_info/ya.make index e7068a0b10..efecba5993 100644 --- a/library/cpp/lfalloc/dbg_info/ya.make +++ b/library/cpp/lfalloc/dbg_info/ya.make @@ -1,15 +1,15 @@ -LIBRARY() +LIBRARY() -OWNER(vskipin) - -PEERDIR( +OWNER(vskipin) + +PEERDIR( library/cpp/malloc/api -) - -SRCS( - dbg_info.cpp -) - -SET(IDE_FOLDER "util") - -END() +) + +SRCS( + dbg_info.cpp +) + +SET(IDE_FOLDER "util") + +END() diff --git a/library/cpp/lfalloc/lf_allocX64.h b/library/cpp/lfalloc/lf_allocX64.h index 616253d689..fd2a906d6f 100644 --- a/library/cpp/lfalloc/lf_allocX64.h +++ b/library/cpp/lfalloc/lf_allocX64.h @@ -37,10 +37,10 @@ static inline long AtomicAdd(TAtomic& a, long b) { return _InterlockedExchangeAdd(&a, b) + b; } -static inline long AtomicSub(TAtomic& a, long b) { - return AtomicAdd(a, -b); -} - +static inline long AtomicSub(TAtomic& a, long b) { + return AtomicAdd(a, -b); +} + #pragma comment(lib, "synchronization.lib") #ifndef NDEBUG @@ -121,7 +121,7 @@ static inline long AtomicSub(TAtomic& a, long b) { #ifndef NDEBUG #define DBG_FILL_MEMORY -static bool FillMemoryOnAllocation = true; +static bool FillMemoryOnAllocation = true; #endif static bool TransparentHugePages = false; // force MADV_HUGEPAGE for large allocs @@ -189,9 +189,9 @@ const int N_SIZES = 25; #endif const int nSizeIdxToSize[N_SIZES] = { -1, -#if defined(_64_) - 16, 16, 32, 32, 48, 64, 96, 128, -#else +#if defined(_64_) + 16, 16, 32, 32, 48, 64, 96, 128, +#else 8, 16, 24, @@ -200,7 +200,7 @@ const int nSizeIdxToSize[N_SIZES] = { 64, 96, 128, -#endif +#endif 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576, 32768, #ifdef LFALLOC_YT @@ -214,11 +214,11 @@ const size_t N_MAX_FAST_SIZE = 32768; #endif const unsigned char size2idxArr1[64 + 1] = { 1, -#if defined(_64_) +#if defined(_64_) 2, 2, 4, 4, // 16, 16, 32, 32 -#else +#else 1, 2, 3, 4, // 8, 16, 24, 32 -#endif +#endif 5, 5, 6, 6, // 48, 64 7, 7, 7, 7, 8, 8, 8, 8, // 96, 128 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, // 192, 256 @@ -312,25 +312,25 @@ inline void VerifyMmapResult(void* result) { static char* AllocWithMMapLinuxImpl(uintptr_t sz, EMMapMode mode) { char* volatile* areaPtr; char* areaStart; - uintptr_t areaFinish; - + uintptr_t areaFinish; + int mapProt = PROT_READ | PROT_WRITE; int mapFlags = MAP_PRIVATE | MAP_ANON; - - if (mode == MM_HUGE) { - areaPtr = reinterpret_cast<char* volatile*>(&linuxAllocPointerHuge); - areaStart = reinterpret_cast<char*>(LINUX_MMAP_AREA_START + N_MAX_WORKSET_SIZE); - areaFinish = N_HUGE_AREA_FINISH; - } else { - areaPtr = reinterpret_cast<char* volatile*>(&linuxAllocPointer); - areaStart = reinterpret_cast<char*>(LINUX_MMAP_AREA_START); - areaFinish = N_MAX_WORKSET_SIZE; - - if (MapHugeTLB) { - mapFlags |= MAP_HUGETLB; - } - } - + + if (mode == MM_HUGE) { + areaPtr = reinterpret_cast<char* volatile*>(&linuxAllocPointerHuge); + areaStart = reinterpret_cast<char*>(LINUX_MMAP_AREA_START + N_MAX_WORKSET_SIZE); + areaFinish = N_HUGE_AREA_FINISH; + } else { + areaPtr = reinterpret_cast<char* volatile*>(&linuxAllocPointer); + areaStart = reinterpret_cast<char*>(LINUX_MMAP_AREA_START); + areaFinish = N_MAX_WORKSET_SIZE; + + if (MapHugeTLB) { + mapFlags |= MAP_HUGETLB; + } + } + bool wrapped = false; for (;;) { char* prevAllocPtr = *areaPtr; @@ -340,24 +340,24 @@ static char* AllocWithMMapLinuxImpl(uintptr_t sz, EMMapMode mode) { NMalloc::AbortFromCorruptedAllocator("virtual memory is over fragmented"); } // wrap after all area is used - DoCas(areaPtr, areaStart, prevAllocPtr); + DoCas(areaPtr, areaStart, prevAllocPtr); wrapped = true; continue; } - if (DoCas(areaPtr, nextAllocPtr, prevAllocPtr) != prevAllocPtr) + if (DoCas(areaPtr, nextAllocPtr, prevAllocPtr) != prevAllocPtr) continue; char* largeBlock = (char*)mmap(prevAllocPtr, sz, mapProt, mapFlags, -1, 0); VerifyMmapResult(largeBlock); if (largeBlock == prevAllocPtr) - return largeBlock; + return largeBlock; if (largeBlock) munmap(largeBlock, sz); if (sz < 0x80000) { // skip utilized area with big steps - DoCas(areaPtr, nextAllocPtr + 0x10 * 0x10000, nextAllocPtr); + DoCas(areaPtr, nextAllocPtr + 0x10 * 0x10000, nextAllocPtr); } } } @@ -367,14 +367,14 @@ static char* AllocWithMMap(uintptr_t sz, EMMapMode mode) { (void)mode; #ifdef _MSC_VER char* largeBlock = (char*)VirtualAlloc(0, sz, MEM_RESERVE, PAGE_READWRITE); - if (Y_UNLIKELY(largeBlock == nullptr)) + if (Y_UNLIKELY(largeBlock == nullptr)) NMalloc::AbortFromCorruptedAllocator("out of memory"); if (Y_UNLIKELY(uintptr_t(((char*)largeBlock - ALLOC_START) + sz) >= N_MAX_WORKSET_SIZE)) NMalloc::AbortFromCorruptedAllocator("out of working set, something has broken"); #else #if defined(_freebsd_) || !defined(_64_) char* largeBlock = (char*)mmap(0, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); - VerifyMmapResult(largeBlock); + VerifyMmapResult(largeBlock); if (Y_UNLIKELY(uintptr_t(((char*)largeBlock - ALLOC_START) + sz) >= N_MAX_WORKSET_SIZE)) NMalloc::AbortFromCorruptedAllocator("out of working set, something has broken"); #else @@ -384,7 +384,7 @@ static char* AllocWithMMap(uintptr_t sz, EMMapMode mode) { } #endif #endif - Y_ASSERT_NOBT(largeBlock); + Y_ASSERT_NOBT(largeBlock); IncrementCounter(CT_MMAP, sz); IncrementCounter(CT_MMAP_CNT, 1); return largeBlock; @@ -779,8 +779,8 @@ static bool DefragmentMem() { return false; } - IncrementCounter(CT_DEGRAGMENT_CNT, 1); - + IncrementCounter(CT_DEGRAGMENT_CNT, 1); + int* nFreeCount = (int*)SystemAlloc(N_CHUNKS * sizeof(int)); if (Y_UNLIKELY(!nFreeCount)) { //__debugbreak(); @@ -886,8 +886,8 @@ enum EDefrag { }; static void* SlowLFAlloc(int nSizeIdx, int blockSize, EDefrag defrag) { - IncrementCounter(CT_SLOW_ALLOC_CNT, 1); - + IncrementCounter(CT_SLOW_ALLOC_CNT, 1); + TLFLockHolder ls; for (;;) { bool locked = ls.TryLock(&LFGlobalLock); @@ -918,9 +918,9 @@ static void* SlowLFAlloc(int nSizeIdx, int blockSize, EDefrag defrag) { } char* largeBlock = AllocWithMMap(N_LARGE_ALLOC_SIZE, MM_NORMAL); - uintptr_t addr = ((largeBlock - ALLOC_START) + N_CHUNK_SIZE - 1) & (~(N_CHUNK_SIZE - 1)); - uintptr_t endAddr = ((largeBlock - ALLOC_START) + N_LARGE_ALLOC_SIZE) & (~(N_CHUNK_SIZE - 1)); - for (uintptr_t p = addr; p < endAddr; p += N_CHUNK_SIZE) { + uintptr_t addr = ((largeBlock - ALLOC_START) + N_CHUNK_SIZE - 1) & (~(N_CHUNK_SIZE - 1)); + uintptr_t endAddr = ((largeBlock - ALLOC_START) + N_LARGE_ALLOC_SIZE) & (~(N_CHUNK_SIZE - 1)); + for (uintptr_t p = addr; p < endAddr; p += N_CHUNK_SIZE) { uintptr_t chunk = p / N_CHUNK_SIZE; Y_ASSERT_NOBT(chunk * N_CHUNK_SIZE == p); Y_ASSERT_NOBT(chunkSizeIdx[chunk] == 0); @@ -1031,70 +1031,70 @@ struct TLocalCounter { } }; -//////////////////////////////////////////////////////////////////////////////// -// DBG stuff -//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// DBG stuff +//////////////////////////////////////////////////////////////////////////////// + +#if defined(LFALLOC_DBG) + +struct TPerTagAllocCounter { + TAtomic Size; + TAtomic Count; -#if defined(LFALLOC_DBG) - -struct TPerTagAllocCounter { - TAtomic Size; - TAtomic Count; - Y_FORCE_INLINE void Alloc(size_t size) { - AtomicAdd(Size, size); - AtomicAdd(Count, 1); - } - + AtomicAdd(Size, size); + AtomicAdd(Count, 1); + } + Y_FORCE_INLINE void Free(size_t size) { - AtomicSub(Size, size); - AtomicSub(Count, 1); - } -}; - -struct TLocalPerTagAllocCounter { - intptr_t Size; - int Count; - int Updates; - + AtomicSub(Size, size); + AtomicSub(Count, 1); + } +}; + +struct TLocalPerTagAllocCounter { + intptr_t Size; + int Count; + int Updates; + Y_FORCE_INLINE void Init() { - Size = 0; - Count = 0; - Updates = 0; - } - + Size = 0; + Count = 0; + Updates = 0; + } + Y_FORCE_INLINE void Alloc(TPerTagAllocCounter& parent, size_t size) { - Size += size; - ++Count; - if (++Updates > MAX_LOCAL_UPDATES) { - Flush(parent); - } - } - + Size += size; + ++Count; + if (++Updates > MAX_LOCAL_UPDATES) { + Flush(parent); + } + } + Y_FORCE_INLINE void Free(TPerTagAllocCounter& parent, size_t size) { - Size -= size; - --Count; - if (++Updates > MAX_LOCAL_UPDATES) { - Flush(parent); - } - } - + Size -= size; + --Count; + if (++Updates > MAX_LOCAL_UPDATES) { + Flush(parent); + } + } + Y_FORCE_INLINE void Flush(TPerTagAllocCounter& parent) { AtomicAdd(parent.Size, Size); Size = 0; AtomicAdd(parent.Count, Count); Count = 0; - Updates = 0; - } -}; - -static const int DBG_ALLOC_MAX_TAG = 1000; + Updates = 0; + } +}; + +static const int DBG_ALLOC_MAX_TAG = 1000; static const int DBG_ALLOC_ALIGNED_TAG = 0xF0000000; -static const int DBG_ALLOC_NUM_SIZES = 30; -static TPerTagAllocCounter GlobalPerTagAllocCounters[DBG_ALLOC_MAX_TAG][DBG_ALLOC_NUM_SIZES]; - +static const int DBG_ALLOC_NUM_SIZES = 30; +static TPerTagAllocCounter GlobalPerTagAllocCounters[DBG_ALLOC_MAX_TAG][DBG_ALLOC_NUM_SIZES]; + #endif // LFALLOC_DBG - + ////////////////////////////////////////////////////////////////////////// const int THREAD_BUF = 256; static int borderSizes[N_SIZES]; @@ -1107,9 +1107,9 @@ struct TThreadAllocInfo { TThreadAllocInfo* pNextInfo; TLocalCounter LocalCounters[CT_MAX]; -#if defined(LFALLOC_DBG) - TLocalPerTagAllocCounter LocalPerTagAllocCounters[DBG_ALLOC_MAX_TAG][DBG_ALLOC_NUM_SIZES]; -#endif +#if defined(LFALLOC_DBG) + TLocalPerTagAllocCounter LocalPerTagAllocCounters[DBG_ALLOC_MAX_TAG][DBG_ALLOC_NUM_SIZES]; +#endif #ifdef _win_ HANDLE hThread; #endif @@ -1136,14 +1136,14 @@ struct TThreadAllocInfo { for (int i = 0; i < CT_MAX; ++i) { LocalCounters[i].Init(&GlobalCounters[i]); } -#if defined(LFALLOC_DBG) - for (int tag = 0; tag < DBG_ALLOC_MAX_TAG; ++tag) { - for (int sizeIdx = 0; sizeIdx < DBG_ALLOC_NUM_SIZES; ++sizeIdx) { - auto& local = LocalPerTagAllocCounters[tag][sizeIdx]; - local.Init(); - } - } -#endif +#if defined(LFALLOC_DBG) + for (int tag = 0; tag < DBG_ALLOC_MAX_TAG; ++tag) { + for (int sizeIdx = 0; sizeIdx < DBG_ALLOC_NUM_SIZES; ++sizeIdx) { + auto& local = LocalPerTagAllocCounters[tag][sizeIdx]; + local.Init(); + } + } +#endif } void Done() { for (auto sizeIdx : FreePtrIndex) { @@ -1152,15 +1152,15 @@ struct TThreadAllocInfo { for (auto& localCounter : LocalCounters) { localCounter.Flush(); } -#if defined(LFALLOC_DBG) - for (int tag = 0; tag < DBG_ALLOC_MAX_TAG; ++tag) { - for (int sizeIdx = 0; sizeIdx < DBG_ALLOC_NUM_SIZES; ++sizeIdx) { - auto& local = LocalPerTagAllocCounters[tag][sizeIdx]; - auto& global = GlobalPerTagAllocCounters[tag][sizeIdx]; - local.Flush(global); - } - } -#endif +#if defined(LFALLOC_DBG) + for (int tag = 0; tag < DBG_ALLOC_MAX_TAG; ++tag) { + for (int sizeIdx = 0; sizeIdx < DBG_ALLOC_NUM_SIZES; ++sizeIdx) { + auto& local = LocalPerTagAllocCounters[tag][sizeIdx]; + auto& global = GlobalPerTagAllocCounters[tag][sizeIdx]; + local.Flush(global); + } + } +#endif #ifdef _win_ if (hThread) CloseHandle(hThread); @@ -1304,21 +1304,21 @@ static void AllocThreadInfo() { // DBG stuff ////////////////////////////////////////////////////////////////////////// -#if defined(LFALLOC_DBG) +#if defined(LFALLOC_DBG) -struct TAllocHeader { +struct TAllocHeader { uint64_t Size; int Tag; - int Cookie; -}; - + int Cookie; +}; + // should be power of 2 static_assert(sizeof(TAllocHeader) == 16); static inline void* GetAllocPtr(TAllocHeader* p) { - return p + 1; -} - + return p + 1; +} + static inline TAllocHeader* GetAllocHeader(void* p) { auto* header = ((TAllocHeader*)p) - 1; if (header->Tag == DBG_ALLOC_ALIGNED_TAG) { @@ -1326,24 +1326,24 @@ static inline TAllocHeader* GetAllocHeader(void* p) { } return header; -} - -PERTHREAD int AllocationTag; +} + +PERTHREAD int AllocationTag; extern "C" int SetThreadAllocTag(int tag) { - int prevTag = AllocationTag; + int prevTag = AllocationTag; if (tag < DBG_ALLOC_MAX_TAG && tag >= 0) { - AllocationTag = tag; - } - return prevTag; -} - -PERTHREAD bool ProfileCurrentThread; + AllocationTag = tag; + } + return prevTag; +} + +PERTHREAD bool ProfileCurrentThread; extern "C" bool SetProfileCurrentThread(bool newVal) { - bool prevVal = ProfileCurrentThread; - ProfileCurrentThread = newVal; - return prevVal; -} - + bool prevVal = ProfileCurrentThread; + ProfileCurrentThread = newVal; + return prevVal; +} + static volatile bool ProfileAllThreads; extern "C" bool SetProfileAllThreads(bool newVal) { bool prevVal = ProfileAllThreads; @@ -1351,176 +1351,176 @@ extern "C" bool SetProfileAllThreads(bool newVal) { return prevVal; } -static volatile bool AllocationSamplingEnabled; +static volatile bool AllocationSamplingEnabled; extern "C" bool SetAllocationSamplingEnabled(bool newVal) { - bool prevVal = AllocationSamplingEnabled; - AllocationSamplingEnabled = newVal; - return prevVal; -} - -static size_t AllocationSampleRate = 1000; + bool prevVal = AllocationSamplingEnabled; + AllocationSamplingEnabled = newVal; + return prevVal; +} + +static size_t AllocationSampleRate = 1000; extern "C" size_t SetAllocationSampleRate(size_t newVal) { - size_t prevVal = AllocationSampleRate; - AllocationSampleRate = newVal; - return prevVal; -} - -static size_t AllocationSampleMaxSize = N_MAX_FAST_SIZE; + size_t prevVal = AllocationSampleRate; + AllocationSampleRate = newVal; + return prevVal; +} + +static size_t AllocationSampleMaxSize = N_MAX_FAST_SIZE; extern "C" size_t SetAllocationSampleMaxSize(size_t newVal) { - size_t prevVal = AllocationSampleMaxSize; - AllocationSampleMaxSize = newVal; - return prevVal; -} - -using TAllocationCallback = int(int tag, size_t size, int sizeIdx); -static TAllocationCallback* AllocationCallback; + size_t prevVal = AllocationSampleMaxSize; + AllocationSampleMaxSize = newVal; + return prevVal; +} + +using TAllocationCallback = int(int tag, size_t size, int sizeIdx); +static TAllocationCallback* AllocationCallback; extern "C" TAllocationCallback* SetAllocationCallback(TAllocationCallback* newVal) { - TAllocationCallback* prevVal = AllocationCallback; - AllocationCallback = newVal; - return prevVal; -} - -using TDeallocationCallback = void(int cookie, int tag, size_t size, int sizeIdx); -static TDeallocationCallback* DeallocationCallback; + TAllocationCallback* prevVal = AllocationCallback; + AllocationCallback = newVal; + return prevVal; +} + +using TDeallocationCallback = void(int cookie, int tag, size_t size, int sizeIdx); +static TDeallocationCallback* DeallocationCallback; extern "C" TDeallocationCallback* SetDeallocationCallback(TDeallocationCallback* newVal) { - TDeallocationCallback* prevVal = DeallocationCallback; - DeallocationCallback = newVal; - return prevVal; -} - -PERTHREAD TAtomic AllocationsCount; -PERTHREAD bool InAllocationCallback; - -static const int DBG_ALLOC_INVALID_COOKIE = -1; + TDeallocationCallback* prevVal = DeallocationCallback; + DeallocationCallback = newVal; + return prevVal; +} + +PERTHREAD TAtomic AllocationsCount; +PERTHREAD bool InAllocationCallback; + +static const int DBG_ALLOC_INVALID_COOKIE = -1; static inline int SampleAllocation(TAllocHeader* p, int sizeIdx) { - int cookie = DBG_ALLOC_INVALID_COOKIE; + int cookie = DBG_ALLOC_INVALID_COOKIE; if (AllocationSamplingEnabled && (ProfileCurrentThread || ProfileAllThreads) && !InAllocationCallback) { - if (p->Size > AllocationSampleMaxSize || ++AllocationsCount % AllocationSampleRate == 0) { - if (AllocationCallback) { - InAllocationCallback = true; - cookie = AllocationCallback(p->Tag, p->Size, sizeIdx); - InAllocationCallback = false; - } - } - } - return cookie; -} - + if (p->Size > AllocationSampleMaxSize || ++AllocationsCount % AllocationSampleRate == 0) { + if (AllocationCallback) { + InAllocationCallback = true; + cookie = AllocationCallback(p->Tag, p->Size, sizeIdx); + InAllocationCallback = false; + } + } + } + return cookie; +} + static inline void SampleDeallocation(TAllocHeader* p, int sizeIdx) { - if (p->Cookie != DBG_ALLOC_INVALID_COOKIE && !InAllocationCallback) { - if (DeallocationCallback) { - InAllocationCallback = true; - DeallocationCallback(p->Cookie, p->Tag, p->Size, sizeIdx); - InAllocationCallback = false; - } - } -} - + if (p->Cookie != DBG_ALLOC_INVALID_COOKIE && !InAllocationCallback) { + if (DeallocationCallback) { + InAllocationCallback = true; + DeallocationCallback(p->Cookie, p->Tag, p->Size, sizeIdx); + InAllocationCallback = false; + } + } +} + static inline void TrackPerTagAllocation(TAllocHeader* p, int sizeIdx) { if (p->Tag < DBG_ALLOC_MAX_TAG && p->Tag >= 0) { Y_ASSERT_NOBT(sizeIdx < DBG_ALLOC_NUM_SIZES); - auto& global = GlobalPerTagAllocCounters[p->Tag][sizeIdx]; - - TThreadAllocInfo* thr = pThreadInfo; - if (thr) { - auto& local = thr->LocalPerTagAllocCounters[p->Tag][sizeIdx]; - local.Alloc(global, p->Size); - } else { - global.Alloc(p->Size); - } - } -} - + auto& global = GlobalPerTagAllocCounters[p->Tag][sizeIdx]; + + TThreadAllocInfo* thr = pThreadInfo; + if (thr) { + auto& local = thr->LocalPerTagAllocCounters[p->Tag][sizeIdx]; + local.Alloc(global, p->Size); + } else { + global.Alloc(p->Size); + } + } +} + static inline void TrackPerTagDeallocation(TAllocHeader* p, int sizeIdx) { if (p->Tag < DBG_ALLOC_MAX_TAG && p->Tag >= 0) { Y_ASSERT_NOBT(sizeIdx < DBG_ALLOC_NUM_SIZES); - auto& global = GlobalPerTagAllocCounters[p->Tag][sizeIdx]; - - TThreadAllocInfo* thr = pThreadInfo; - if (thr) { - auto& local = thr->LocalPerTagAllocCounters[p->Tag][sizeIdx]; - local.Free(global, p->Size); - } else { - global.Free(p->Size); - } - } -} - + auto& global = GlobalPerTagAllocCounters[p->Tag][sizeIdx]; + + TThreadAllocInfo* thr = pThreadInfo; + if (thr) { + auto& local = thr->LocalPerTagAllocCounters[p->Tag][sizeIdx]; + local.Free(global, p->Size); + } else { + global.Free(p->Size); + } + } +} + static void* TrackAllocation(void* ptr, size_t size, int sizeIdx) { - TAllocHeader* p = (TAllocHeader*)ptr; - p->Size = size; - p->Tag = AllocationTag; - p->Cookie = SampleAllocation(p, sizeIdx); - TrackPerTagAllocation(p, sizeIdx); - return GetAllocPtr(p); -} - + TAllocHeader* p = (TAllocHeader*)ptr; + p->Size = size; + p->Tag = AllocationTag; + p->Cookie = SampleAllocation(p, sizeIdx); + TrackPerTagAllocation(p, sizeIdx); + return GetAllocPtr(p); +} + static void TrackDeallocation(void* ptr, int sizeIdx) { - TAllocHeader* p = (TAllocHeader*)ptr; - SampleDeallocation(p, sizeIdx); - TrackPerTagDeallocation(p, sizeIdx); -} - -struct TPerTagAllocInfo { - ssize_t Count; - ssize_t Size; -}; - -extern "C" void GetPerTagAllocInfo( - bool flushPerThreadCounters, - TPerTagAllocInfo* info, - int& maxTag, + TAllocHeader* p = (TAllocHeader*)ptr; + SampleDeallocation(p, sizeIdx); + TrackPerTagDeallocation(p, sizeIdx); +} + +struct TPerTagAllocInfo { + ssize_t Count; + ssize_t Size; +}; + +extern "C" void GetPerTagAllocInfo( + bool flushPerThreadCounters, + TPerTagAllocInfo* info, + int& maxTag, int& numSizes) { - maxTag = DBG_ALLOC_MAX_TAG; - numSizes = DBG_ALLOC_NUM_SIZES; - - if (info) { - if (flushPerThreadCounters) { + maxTag = DBG_ALLOC_MAX_TAG; + numSizes = DBG_ALLOC_NUM_SIZES; + + if (info) { + if (flushPerThreadCounters) { TLFLockHolder ll(&LFLockThreadInfo); for (TThreadAllocInfo** p = &pThreadInfoList; *p;) { TThreadAllocInfo* pInfo = *p; - for (int tag = 0; tag < DBG_ALLOC_MAX_TAG; ++tag) { - for (int sizeIdx = 0; sizeIdx < DBG_ALLOC_NUM_SIZES; ++sizeIdx) { - auto& local = pInfo->LocalPerTagAllocCounters[tag][sizeIdx]; - auto& global = GlobalPerTagAllocCounters[tag][sizeIdx]; - local.Flush(global); - } - } - p = &pInfo->pNextInfo; - } - } - - for (int tag = 0; tag < DBG_ALLOC_MAX_TAG; ++tag) { - for (int sizeIdx = 0; sizeIdx < DBG_ALLOC_NUM_SIZES; ++sizeIdx) { - auto& global = GlobalPerTagAllocCounters[tag][sizeIdx]; + for (int tag = 0; tag < DBG_ALLOC_MAX_TAG; ++tag) { + for (int sizeIdx = 0; sizeIdx < DBG_ALLOC_NUM_SIZES; ++sizeIdx) { + auto& local = pInfo->LocalPerTagAllocCounters[tag][sizeIdx]; + auto& global = GlobalPerTagAllocCounters[tag][sizeIdx]; + local.Flush(global); + } + } + p = &pInfo->pNextInfo; + } + } + + for (int tag = 0; tag < DBG_ALLOC_MAX_TAG; ++tag) { + for (int sizeIdx = 0; sizeIdx < DBG_ALLOC_NUM_SIZES; ++sizeIdx) { + auto& global = GlobalPerTagAllocCounters[tag][sizeIdx]; auto& res = info[tag * DBG_ALLOC_NUM_SIZES + sizeIdx]; - res.Count = global.Count; - res.Size = global.Size; - } - } - } -} - + res.Count = global.Count; + res.Size = global.Size; + } + } + } +} + #endif // LFALLOC_DBG - + ////////////////////////////////////////////////////////////////////////// static Y_FORCE_INLINE void* LFAllocImpl(size_t _nSize) { -#if defined(LFALLOC_DBG) - size_t size = _nSize; - _nSize += sizeof(TAllocHeader); -#endif - +#if defined(LFALLOC_DBG) + size_t size = _nSize; + _nSize += sizeof(TAllocHeader); +#endif + IncrementCounter(CT_USER_ALLOC, _nSize); int nSizeIdx; if (_nSize > 512) { - if (_nSize > N_MAX_FAST_SIZE) { - void* ptr = LargeBlockAlloc(_nSize, CT_LARGE_ALLOC); -#if defined(LFALLOC_DBG) - ptr = TrackAllocation(ptr, size, N_SIZES); -#endif - return ptr; - } + if (_nSize > N_MAX_FAST_SIZE) { + void* ptr = LargeBlockAlloc(_nSize, CT_LARGE_ALLOC); +#if defined(LFALLOC_DBG) + ptr = TrackAllocation(ptr, size, N_SIZES); +#endif + return ptr; + } nSizeIdx = size2idxArr2[(_nSize - 1) >> 8]; } else nSizeIdx = size2idxArr1[1 + (((int)_nSize - 1) >> 3)]; @@ -1533,22 +1533,22 @@ static Y_FORCE_INLINE void* LFAllocImpl(size_t _nSize) { AllocThreadInfo(); thr = pThreadInfo; if (!thr) { - void* ptr = LFAllocNoCache(nSizeIdx, MEM_DEFRAG); -#if defined(LFALLOC_DBG) - ptr = TrackAllocation(ptr, size, nSizeIdx); -#endif - return ptr; + void* ptr = LFAllocNoCache(nSizeIdx, MEM_DEFRAG); +#if defined(LFALLOC_DBG) + ptr = TrackAllocation(ptr, size, nSizeIdx); +#endif + return ptr; } } { int& freePtrIdx = thr->FreePtrIndex[nSizeIdx]; - if (freePtrIdx < THREAD_BUF) { - void* ptr = thr->FreePtrs[nSizeIdx][freePtrIdx++]; -#if defined(LFALLOC_DBG) - ptr = TrackAllocation(ptr, size, nSizeIdx); -#endif - return ptr; - } + if (freePtrIdx < THREAD_BUF) { + void* ptr = thr->FreePtrs[nSizeIdx][freePtrIdx++]; +#if defined(LFALLOC_DBG) + ptr = TrackAllocation(ptr, size, nSizeIdx); +#endif + return ptr; + } // try to alloc from global free list char* buf[FL_GROUP_SIZE]; @@ -1563,11 +1563,11 @@ static Y_FORCE_INLINE void* LFAllocImpl(size_t _nSize) { for (int i = 0; i < count - 1; ++i) dstBuf[-i] = buf[i]; freePtrIdx -= count - 1; - void* ptr = buf[count - 1]; -#if defined(LFALLOC_DBG) - ptr = TrackAllocation(ptr, size, nSizeIdx); -#endif - return ptr; + void* ptr = buf[count - 1]; +#if defined(LFALLOC_DBG) + ptr = TrackAllocation(ptr, size, nSizeIdx); +#endif + return ptr; } } @@ -1582,33 +1582,33 @@ static Y_FORCE_INLINE void* LFAlloc(size_t _nSize) { } static Y_FORCE_INLINE void LFFree(void* p) { -#if defined(LFALLOC_DBG) - if (p == nullptr) - return; - p = GetAllocHeader(p); -#endif - +#if defined(LFALLOC_DBG) + if (p == nullptr) + return; + p = GetAllocHeader(p); +#endif + uintptr_t chkOffset = ((char*)p - ALLOC_START) - 1ll; if (chkOffset >= N_MAX_WORKSET_SIZE) { if (p == nullptr) return; -#if defined(LFALLOC_DBG) - TrackDeallocation(p, N_SIZES); -#endif +#if defined(LFALLOC_DBG) + TrackDeallocation(p, N_SIZES); +#endif LargeBlockFree(p, CT_LARGE_FREE); return; } - + uintptr_t chunk = ((char*)p - ALLOC_START) / N_CHUNK_SIZE; ptrdiff_t nSizeIdx = chunkSizeIdx[chunk]; if (nSizeIdx <= 0) { -#if defined(LFALLOC_DBG) - TrackDeallocation(p, N_SIZES); -#endif +#if defined(LFALLOC_DBG) + TrackDeallocation(p, N_SIZES); +#endif LargeBlockFree(p, CT_LARGE_FREE); return; } - + #if defined(LFALLOC_DBG) TrackDeallocation(p, nSizeIdx); #endif @@ -1645,12 +1645,12 @@ static Y_FORCE_INLINE void LFFree(void* p) { } static size_t LFGetSize(const void* p) { -#if defined(LFALLOC_DBG) - if (p == nullptr) - return 0; +#if defined(LFALLOC_DBG) + if (p == nullptr) + return 0; return GetAllocHeader(const_cast<void*>(p))->Size; -#endif - +#endif + uintptr_t chkOffset = ((const char*)p - ALLOC_START); if (chkOffset >= N_MAX_WORKSET_SIZE) { if (p == nullptr) @@ -1827,10 +1827,10 @@ static bool LFAlloc_SetParam(const char* param, const char* value) { TransparentHugePages = !strcmp(value, "true"); return true; } - if (!strcmp(param, "MapHugeTLB")) { - MapHugeTLB = !strcmp(value, "true"); - return true; - } + if (!strcmp(param, "MapHugeTLB")) { + MapHugeTLB = !strcmp(value, "true"); + return true; + } if (!strcmp(param, "EnableDefrag")) { EnableDefrag = !strcmp(value, "true"); return true; @@ -1839,15 +1839,15 @@ static bool LFAlloc_SetParam(const char* param, const char* value) { }; static const char* LFAlloc_GetParam(const char* param) { - struct TParam { - const char* Name; - const char* Value; - }; - - static const TParam Params[] = { + struct TParam { + const char* Name; + const char* Value; + }; + + static const TParam Params[] = { {"GetLFAllocCounterFast", (const char*)&GetLFAllocCounterFast}, {"GetLFAllocCounterFull", (const char*)&GetLFAllocCounterFull}, -#if defined(LFALLOC_DBG) +#if defined(LFALLOC_DBG) {"SetThreadAllocTag", (const char*)&SetThreadAllocTag}, {"SetProfileCurrentThread", (const char*)&SetProfileCurrentThread}, {"SetProfileAllThreads", (const char*)&SetProfileAllThreads}, @@ -1858,12 +1858,12 @@ static const char* LFAlloc_GetParam(const char* param) { {"SetDeallocationCallback", (const char*)&SetDeallocationCallback}, {"GetPerTagAllocInfo", (const char*)&GetPerTagAllocInfo}, #endif // LFALLOC_DBG - }; - - for (int i = 0; i < Y_ARRAY_SIZE(Params); ++i) { - if (strcmp(param, Params[i].Name) == 0) { - return Params[i].Value; - } + }; + + for (int i = 0; i < Y_ARRAY_SIZE(Params); ++i) { + if (strcmp(param, Params[i].Name) == 0) { + return Params[i].Value; + } } return nullptr; } diff --git a/library/cpp/messagebus/actor/executor.cpp b/library/cpp/messagebus/actor/executor.cpp index d0ed3647fa..7a2227a458 100644 --- a/library/cpp/messagebus/actor/executor.cpp +++ b/library/cpp/messagebus/actor/executor.cpp @@ -176,7 +176,7 @@ TExecutor::TExecutor(const TExecutor::TConfig& config) void TExecutor::Init() { Impl.Reset(new TImpl(this)); - AtomicSet(ExitWorkers, 0); + AtomicSet(ExitWorkers, 0); Y_VERIFY(Config.WorkerCount > 0); @@ -192,7 +192,7 @@ TExecutor::~TExecutor() { } void TExecutor::Stop() { - AtomicSet(ExitWorkers, 1); + AtomicSet(ExitWorkers, 1); Impl->HelperStopSignal.Signal(); Impl->HelperThread.Join(); @@ -214,7 +214,7 @@ void TExecutor::EnqueueWork(TArrayRef<IWorkItem* const> wis) { if (wis.empty()) return; - if (Y_UNLIKELY(AtomicGet(ExitWorkers) != 0)) { + if (Y_UNLIKELY(AtomicGet(ExitWorkers) != 0)) { Y_VERIFY(WorkItems.Empty(), "executor %s: cannot add tasks after queue shutdown", Config.Name); } @@ -289,7 +289,7 @@ TAutoPtr<IWorkItem> TExecutor::DequeueWork() { if (!WorkItems.TryPop(&wi, &queueSize)) { TWhatThreadDoesAcquireGuard<TMutex> g(WorkMutex, "executor: acquiring lock for DequeueWork"); while (!WorkItems.TryPop(&wi, &queueSize)) { - if (AtomicGet(ExitWorkers) != 0) + if (AtomicGet(ExitWorkers) != 0) return nullptr; TWhatThreadDoesPushPop pp("waiting for work on condvar"); diff --git a/library/cpp/messagebus/actor/ring_buffer_with_spin_lock.h b/library/cpp/messagebus/actor/ring_buffer_with_spin_lock.h index b49bfd6cfb..f0b7cd90e4 100644 --- a/library/cpp/messagebus/actor/ring_buffer_with_spin_lock.h +++ b/library/cpp/messagebus/actor/ring_buffer_with_spin_lock.h @@ -9,11 +9,11 @@ class TRingBufferWithSpinLock { private: TRingBuffer<T> RingBuffer; TSpinLock SpinLock; - TAtomic CachedSize; - + TAtomic CachedSize; + public: TRingBufferWithSpinLock() - : CachedSize(0) + : CachedSize(0) { } @@ -28,11 +28,11 @@ public: TGuard<TSpinLock> Guard(SpinLock); RingBuffer.PushAll(collection); - AtomicSet(CachedSize, RingBuffer.Size()); + AtomicSet(CachedSize, RingBuffer.Size()); } bool TryPop(T* r, size_t* sizePtr = nullptr) { - if (AtomicGet(CachedSize) == 0) { + if (AtomicGet(CachedSize) == 0) { return false; } @@ -42,7 +42,7 @@ public: TGuard<TSpinLock> Guard(SpinLock); ok = RingBuffer.TryPop(r); size = RingBuffer.Size(); - AtomicSet(CachedSize, size); + AtomicSet(CachedSize, size); } if (!!sizePtr) { *sizePtr = size; @@ -63,25 +63,25 @@ public: if (collection.size() == 0) { return TryPop(r); } else { - if (AtomicGet(CachedSize) == 0) { + if (AtomicGet(CachedSize) == 0) { *r = collection[0]; if (collection.size() > 1) { TGuard<TSpinLock> guard(SpinLock); RingBuffer.PushAll(MakeArrayRef(collection.data() + 1, collection.size() - 1)); - AtomicSet(CachedSize, RingBuffer.Size()); + AtomicSet(CachedSize, RingBuffer.Size()); } } else { TGuard<TSpinLock> guard(SpinLock); RingBuffer.PushAll(collection); *r = RingBuffer.Pop(); - AtomicSet(CachedSize, RingBuffer.Size()); + AtomicSet(CachedSize, RingBuffer.Size()); } return true; } } bool Empty() const { - return AtomicGet(CachedSize) == 0; + return AtomicGet(CachedSize) == 0; } size_t Size() const { diff --git a/library/cpp/messagebus/event_loop.cpp b/library/cpp/messagebus/event_loop.cpp index 6946ccdea4..f685135bed 100644 --- a/library/cpp/messagebus/event_loop.cpp +++ b/library/cpp/messagebus/event_loop.cpp @@ -79,7 +79,7 @@ public: const char* Name; TAtomic RunningState; - TAtomic StopSignal; + TAtomic StopSignal; TSystemEvent StoppedEvent; TData Data; @@ -255,7 +255,7 @@ void TChannel::TImpl::CallHandler() { TEventLoop::TImpl::TImpl(const char* name) : Name(name) , RunningState(EVENT_LOOP_CREATED) - , StopSignal(0) + , StopSignal(0) { SOCKET wakeupSockets[2]; @@ -284,7 +284,7 @@ void TEventLoop::TImpl::Run() { SetCurrentThreadName(Name); } - while (AtomicGet(StopSignal) == 0) { + while (AtomicGet(StopSignal) == 0) { void* cookies[1024]; const size_t count = Poller.WaitI(cookies, Y_ARRAY_SIZE(cookies)); @@ -328,7 +328,7 @@ void TEventLoop::TImpl::Run() { } void TEventLoop::TImpl::Stop() { - AtomicSet(StopSignal, 1); + AtomicSet(StopSignal, 1); if (AtomicGet(RunningState) == EVENT_LOOP_RUNNING) { Wakeup(); diff --git a/library/cpp/messagebus/futex_like.h b/library/cpp/messagebus/futex_like.h index f40594918f..31d60c60f1 100644 --- a/library/cpp/messagebus/futex_like.h +++ b/library/cpp/messagebus/futex_like.h @@ -39,7 +39,7 @@ public: #ifdef _linux_ return __atomic_exchange_n(&Value, newValue, __ATOMIC_SEQ_CST); #else - return AtomicSwap(&Value, newValue); + return AtomicSwap(&Value, newValue); #endif } #endif diff --git a/library/cpp/messagebus/misc/tokenquota.h b/library/cpp/messagebus/misc/tokenquota.h index 656da42b10..190547fa54 100644 --- a/library/cpp/messagebus/misc/tokenquota.h +++ b/library/cpp/messagebus/misc/tokenquota.h @@ -29,7 +29,7 @@ namespace NBus { level = Max(TAtomicBase(level), TAtomicBase(1)); if (Enabled && (Acquired < level || force)) { - Acquired += AtomicSwap(&Tokens_, 0); + Acquired += AtomicSwap(&Tokens_, 0); } return !Enabled || Acquired >= level; diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index fb3139d055..0dfe57bc7a 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -636,21 +636,21 @@ Y_UNIT_TEST(TestCastFromString) { Y_UNIT_TEST(TestMap) { TMapType modelProto; - + auto& items = *modelProto.MutableItems(); items["key1"] = "value1"; items["key2"] = "value2"; items["key3"] = "value3"; - + TString modelStr(R"_({"Items":[{"key":"key3","value":"value3"},{"key":"key2","value":"value2"},{"key":"key1","value":"value1"}]})_"); - + TJson2ProtoConfig config; TMapType proto; UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TMapType>(modelStr, config)); - + UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); } // TestMap - + Y_UNIT_TEST(TestCastRobust) { NJson::TJsonValue json; json["I32"] = "5"; diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index faab2efeaf..07e52d7f2f 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -901,21 +901,21 @@ Y_UNIT_TEST(TestInf) { UNIT_ASSERT_EXCEPTION(Proto2Json(proto, TProto2JsonConfig()), yexception); } // TestInf - + Y_UNIT_TEST(TestMap) { TMapType proto; - + auto& items = *proto.MutableItems(); items["key1"] = "value1"; items["key2"] = "value2"; items["key3"] = "value3"; - + TString modelStr(R"_({"Items":[{"key":"key3","value":"value3"},{"key":"key2","value":"value2"},{"key":"key1","value":"value1"}]})_"); - + TStringStream jsonStr; TProto2JsonConfig config; UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config)); - + NJson::TJsonValue jsonValue, modelValue; NJson::TJsonValue::TArray jsonItems, modelItems; UNIT_ASSERT(NJson::ReadJsonTree(jsonStr.Str(), &jsonValue)); @@ -930,7 +930,7 @@ Y_UNIT_TEST(TestMap) { SortBy(modelItems, itemKey); UNIT_ASSERT_EQUAL(jsonItems, modelItems); } // TestMap - + Y_UNIT_TEST(TestMapAsObject) { TMapType proto; @@ -951,20 +951,20 @@ Y_UNIT_TEST(TestMapAsObject) { Y_UNIT_TEST(TestMapWTF) { TMapType proto; - + auto& items = *proto.MutableItems(); items["key1"] = "value1"; items["key2"] = "value2"; items["key3"] = "value3"; - + TString modelStr(R"_({"Items":{"key3":"value3","key2":"value2","key1":"value1"}})_"); - + TStringStream jsonStr; UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr)); - + UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); } // TestMapWTF - + Y_UNIT_TEST(TestStringifyLongNumbers) { #define TEST_SINGLE(flag, value, expectString) \ do { \ diff --git a/library/cpp/protobuf/json/ut/test.proto b/library/cpp/protobuf/json/ut/test.proto index 8449399c81..0fa996fd41 100644 --- a/library/cpp/protobuf/json/ut/test.proto +++ b/library/cpp/protobuf/json/ut/test.proto @@ -130,10 +130,10 @@ message TCompositeRequired { message TCompositeRepeated { repeated TFlatOptional Part = 1; }; - + message TMapType { - map<string, string> Items = 1; -}; + map<string, string> Items = 1; +}; message TNameGeneratorType { optional int32 Field = 1; diff --git a/library/cpp/scheme/scheme.h b/library/cpp/scheme/scheme.h index 857a7fb9e0..3d7c59f3c9 100644 --- a/library/cpp/scheme/scheme.h +++ b/library/cpp/scheme/scheme.h @@ -388,7 +388,7 @@ namespace NSc { static TValue From(const ::google::protobuf::Message&, bool mapAsDict = false); void To(::google::protobuf::Message&, const TProtoOpts& opts = {}) const; - + public: inline explicit TValue(TPoolPtr&); @@ -420,7 +420,7 @@ namespace NSc { static TValue FromField(const ::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*); static TValue FromRepeatedField(const ::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*, int index); - + void ValueToField(const TValue& value, ::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*, const TProtoOpts& opts) const; void ToField(::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*, const TProtoOpts& opts) const; void ToEnumField(::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*, const TProtoOpts& opts) const; diff --git a/library/cpp/scheme/scimpl_protobuf.cpp b/library/cpp/scheme/scimpl_protobuf.cpp index e24be0aad3..0c99122c69 100644 --- a/library/cpp/scheme/scimpl_protobuf.cpp +++ b/library/cpp/scheme/scimpl_protobuf.cpp @@ -130,41 +130,41 @@ namespace NSc { } void TValue::To(Message& msg, const TProtoOpts& opts) const { - msg.Clear(); - - if (IsNull()) { - return; - } - - if (!IsDict()) { - ythrow TSchemeException() << "expected dictionary"; - } - - const Descriptor* descriptor = msg.GetDescriptor(); - for (int i = 0, count = descriptor->field_count(); i < count; ++i) { - const FieldDescriptor* field = descriptor->field(i); + msg.Clear(); + + if (IsNull()) { + return; + } + + if (!IsDict()) { + ythrow TSchemeException() << "expected dictionary"; + } + + const Descriptor* descriptor = msg.GetDescriptor(); + for (int i = 0, count = descriptor->field_count(); i < count; ++i) { + const FieldDescriptor* field = descriptor->field(i); if (field->is_map()) { ToMapField(msg, field, opts); } else if (field->is_repeated()) { ToRepeatedField(msg, field, opts); - } else { + } else { ToField(msg, field, opts); - } - } - } - + } + } + } + void TValue::ValueToField(const TValue& value, Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const { const TString& name = field->name(); - if (value.IsNull()) { - if (field->is_required() && !field->has_default_value()) { - ythrow TSchemeException() << "has no value for required field " << name; - } - return; - } - - const Reflection* reflection = msg.GetReflection(); - - switch (field->cpp_type()) { + if (value.IsNull()) { + if (field->is_required() && !field->has_default_value()) { + ythrow TSchemeException() << "has no value for required field " << name; + } + return; + } + + const Reflection* reflection = msg.GetReflection(); + + switch (field->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: reflection->SetInt32(&msg, field, value.ForceIntNumber()); break; @@ -199,9 +199,9 @@ namespace NSc { ythrow TSchemeException() << "field " << field->full_name() << " unexpected type " << (int)field->cpp_type(); - } - } - + } + } + void TValue::ToField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const { const TString& name = field->name(); const TValue& value = Get(name); @@ -209,49 +209,49 @@ namespace NSc { } void TValue::ToEnumField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const { - const EnumDescriptor* enumField = field->enum_type(); - - const EnumValueDescriptor* enumFieldValue = IsString() + const EnumDescriptor* enumField = field->enum_type(); + + const EnumValueDescriptor* enumFieldValue = IsString() ? enumField->FindValueByName(ForceString()) : enumField->FindValueByNumber(ForceIntNumber()); - - if (!enumFieldValue) { + + if (!enumFieldValue) { if (opts.UnknownEnumValueIsDefault) { enumFieldValue = field->default_value_enum(); } else { ythrow TSchemeException() << "invalid value of enum field " << field->name(); } - } - - const Reflection* reflection = msg.GetReflection(); - - if (field->is_repeated()) { - reflection->AddEnum(&msg, field, enumFieldValue); - } else { - reflection->SetEnum(&msg, field, enumFieldValue); - } - } - + } + + const Reflection* reflection = msg.GetReflection(); + + if (field->is_repeated()) { + reflection->AddEnum(&msg, field, enumFieldValue); + } else { + reflection->SetEnum(&msg, field, enumFieldValue); + } + } + void TValue::ToRepeatedField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const { const TString& name = field->name(); - - const TValue& fieldValue = Get(name); - if (fieldValue.IsNull()) { - return; - } - - if (!fieldValue.IsArray()) { + + const TValue& fieldValue = Get(name); + if (fieldValue.IsNull()) { + return; + } + + if (!fieldValue.IsArray()) { if (opts.SkipTypeMismatch) { return; // leave repeated field empty } else { ythrow TSchemeException() << "invalid type of repeated field " << name << ": not an array"; } - } - - const Reflection* reflection = msg.GetReflection(); - + } + + const Reflection* reflection = msg.GetReflection(); + for (const TValue& value : fieldValue.GetArray()) { - switch (field->cpp_type()) { + switch (field->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: reflection->AddInt32(&msg, field, value.ForceIntNumber()); break; @@ -286,10 +286,10 @@ namespace NSc { ythrow TSchemeException() << "field " << field->full_name() << " unexpected type " << (int)field->cpp_type(); - } - } - } - + } + } + } + void TValue::ToMapField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const { const TString& name = field->name(); diff --git a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp index 24c2addac9..e711a0d092 100644 --- a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp +++ b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp @@ -8,12 +8,12 @@ Y_UNIT_TEST_SUITE(TSchemeProtoTest) { Y_UNIT_TEST(TestFromProtobuf) { DoTestProtobuf(true, false); - } - + } + Y_UNIT_TEST(TestToProtobuf) { DoTestProtobuf(false, false); - } - + } + Y_UNIT_TEST(TestFromProtobufWithDict) { DoTestProtobuf(true, true); } @@ -207,14 +207,14 @@ Y_UNIT_TEST_SUITE(TSchemeProtoTest) { *(m.AddMessages()) = m2, v["Messages"][0] = v2; *(m.AddMessages()) = m2, v["Messages"][1] = v2; - if (fromProto) { + if (fromProto) { UNIT_ASSERT(NSc::TValue::Equal(v, NSc::TValue::From(m, mapAsDict))); - } else { - NSc::TMessage proto; - v.To(proto); - + } else { + NSc::TMessage proto; + v.To(proto); + TString differentPath; - UNIT_ASSERT_C(NProtoBuf::IsEqual(m, proto, &differentPath), differentPath); - } + UNIT_ASSERT_C(NProtoBuf::IsEqual(m, proto, &differentPath), differentPath); + } } }; diff --git a/library/cpp/threading/chunk_queue/queue.cpp b/library/cpp/threading/chunk_queue/queue.cpp index 52dd119921..4ebd3f3205 100644 --- a/library/cpp/threading/chunk_queue/queue.cpp +++ b/library/cpp/threading/chunk_queue/queue.cpp @@ -1 +1 @@ -#include "queue.h" +#include "queue.h" diff --git a/library/cpp/threading/chunk_queue/queue.h b/library/cpp/threading/chunk_queue/queue.h index fdf4c93f92..55859601a1 100644 --- a/library/cpp/threading/chunk_queue/queue.h +++ b/library/cpp/threading/chunk_queue/queue.h @@ -1,35 +1,35 @@ -#pragma once - -#include <util/datetime/base.h> -#include <util/generic/noncopyable.h> -#include <util/generic/ptr.h> -#include <util/generic/typetraits.h> -#include <util/generic/vector.h> -#include <util/generic/ylimits.h> -#include <util/system/atomic.h> -#include <util/system/guard.h> -#include <util/system/spinlock.h> -#include <util/system/yassert.h> - -#include <type_traits> -#include <utility> - -namespace NThreading { -//////////////////////////////////////////////////////////////////////////////// -// Platform helpers - -#if !defined(PLATFORM_CACHE_LINE) +#pragma once + +#include <util/datetime/base.h> +#include <util/generic/noncopyable.h> +#include <util/generic/ptr.h> +#include <util/generic/typetraits.h> +#include <util/generic/vector.h> +#include <util/generic/ylimits.h> +#include <util/system/atomic.h> +#include <util/system/guard.h> +#include <util/system/spinlock.h> +#include <util/system/yassert.h> + +#include <type_traits> +#include <utility> + +namespace NThreading { +//////////////////////////////////////////////////////////////////////////////// +// Platform helpers + +#if !defined(PLATFORM_CACHE_LINE) #define PLATFORM_CACHE_LINE 64 -#endif - -#if !defined(PLATFORM_PAGE_SIZE) +#endif + +#if !defined(PLATFORM_PAGE_SIZE) #define PLATFORM_PAGE_SIZE 4 * 1024 -#endif - +#endif + template <typename T, size_t PadSize = PLATFORM_CACHE_LINE> struct TPadded: public T { char Pad[PadSize - sizeof(T) % PadSize]; - + TPadded() { static_assert(sizeof(*this) % PadSize == 0, "padding does not work"); Y_UNUSED(Pad); @@ -43,10 +43,10 @@ namespace NThreading { Y_UNUSED(Pad); } }; - + //////////////////////////////////////////////////////////////////////////////// // Type helpers - + namespace NImpl { template <typename T> struct TPodTypeHelper { @@ -54,99 +54,99 @@ namespace NThreading { static void Write(T* ptr, TT&& value) { *ptr = value; } - + static T Read(T* ptr) { return *ptr; } - + static void Destroy(T* ptr) { Y_UNUSED(ptr); } }; - + template <typename T> struct TNonPodTypeHelper { template <typename TT> static void Write(T* ptr, TT&& value) { new (ptr) T(std::forward<TT>(value)); } - + static T Read(T* ptr) { return std::move(*ptr); } - + static void Destroy(T* ptr) { (void)ptr; /* Make MSVC happy. */ ptr->~T(); } }; - + template <typename T> using TTypeHelper = std::conditional_t< TTypeTraits<T>::IsPod, TPodTypeHelper<T>, TNonPodTypeHelper<T>>; - + } - + //////////////////////////////////////////////////////////////////////////////// // One producer/one consumer chunked queue. - + template <typename T, size_t ChunkSize = PLATFORM_PAGE_SIZE> class TOneOneQueue: private TNonCopyable { using TTypeHelper = NImpl::TTypeHelper<T>; - + struct TChunk; - + struct TChunkHeader { size_t Count = 0; TChunk* Next = nullptr; }; - + struct TChunk: public TChunkHeader { static constexpr size_t MaxCount = (ChunkSize - sizeof(TChunkHeader)) / sizeof(T); - + char Entries[MaxCount * sizeof(T)]; - + TChunk() { Y_UNUSED(Entries); // uninitialized } - + ~TChunk() { for (size_t i = 0; i < this->Count; ++i) { TTypeHelper::Destroy(GetPtr(i)); } - } - + } + T* GetPtr(size_t i) { return (T*)Entries + i; } }; - + struct TWriterState { TChunk* Chunk = nullptr; }; - + struct TReaderState { TChunk* Chunk = nullptr; size_t Count = 0; }; - + private: TPadded<TWriterState> Writer; TPadded<TReaderState> Reader; - + public: using TItem = T; - + TOneOneQueue() { Writer.Chunk = Reader.Chunk = new TChunk(); } - + ~TOneOneQueue() { DeleteChunks(Reader.Chunk); } - + template <typename TT> void Enqueue(TT&& value) { T* ptr = PrepareWrite(); @@ -154,7 +154,7 @@ namespace NThreading { TTypeHelper::Write(ptr, std::forward<TT>(value)); CompleteWrite(); } - + bool Dequeue(T& value) { if (T* ptr = PrepareRead()) { value = TTypeHelper::Read(ptr); @@ -162,17 +162,17 @@ namespace NThreading { return true; } return false; - } - + } + bool IsEmpty() { return !PrepareRead(); } - + protected: T* PrepareWrite() { TChunk* chunk = Writer.Chunk; Y_ASSERT(chunk && !chunk->Next); - + if (chunk->Count != TChunk::MaxCount) { return chunk->GetPtr(chunk->Count); } @@ -181,41 +181,41 @@ namespace NThreading { AtomicSet(Writer.Chunk->Next, chunk); Writer.Chunk = chunk; return chunk->GetPtr(0); - } - + } + void CompleteWrite() { AtomicSet(Writer.Chunk->Count, Writer.Chunk->Count + 1); } - + T* PrepareRead() { TChunk* chunk = Reader.Chunk; Y_ASSERT(chunk); - + for (;;) { size_t writerCount = AtomicGet(chunk->Count); if (Reader.Count != writerCount) { return chunk->GetPtr(Reader.Count); } - + if (writerCount != TChunk::MaxCount) { return nullptr; } - + chunk = AtomicGet(chunk->Next); if (!chunk) { return nullptr; } - + delete Reader.Chunk; Reader.Chunk = chunk; Reader.Count = 0; - } + } } - + void CompleteRead() { ++Reader.Count; - } - + } + private: static void DeleteChunks(TChunk* chunk) { while (chunk) { @@ -223,51 +223,51 @@ namespace NThreading { delete chunk; chunk = next; } - } + } }; - + //////////////////////////////////////////////////////////////////////////////// // Multiple producers/single consumer partitioned queue. // Provides FIFO guaranties for each producer. - + template <typename T, size_t Concurrency = 4, size_t ChunkSize = PLATFORM_PAGE_SIZE> class TManyOneQueue: private TNonCopyable { using TTypeHelper = NImpl::TTypeHelper<T>; - + struct TEntry { T Value; ui64 Tag; }; - + struct TQueueType: public TOneOneQueue<TEntry, ChunkSize> { TAtomic WriteLock = 0; - + using TOneOneQueue<TEntry, ChunkSize>::PrepareWrite; using TOneOneQueue<TEntry, ChunkSize>::CompleteWrite; - + using TOneOneQueue<TEntry, ChunkSize>::PrepareRead; using TOneOneQueue<TEntry, ChunkSize>::CompleteRead; }; - + private: union { TAtomic WriteTag = 0; char Pad[PLATFORM_CACHE_LINE]; }; - + TQueueType Queues[Concurrency]; - + public: using TItem = T; - + template <typename TT> void Enqueue(TT&& value) { ui64 tag = NextTag(); while (!TryEnqueue(std::forward<TT>(value), tag)) { SpinLockPause(); } - } - + } + bool Dequeue(T& value) { size_t index = 0; if (TEntry* entry = PrepareRead(index)) { @@ -276,24 +276,24 @@ namespace NThreading { return true; } return false; - } - + } + bool IsEmpty() { for (size_t i = 0; i < Concurrency; ++i) { if (!Queues[i].IsEmpty()) { return false; } - } + } return true; - } - + } + private: ui64 NextTag() { // TODO: can we avoid synchronization here? it costs 1.5x performance penalty // return GetCycleCount(); return AtomicIncrement(WriteTag); } - + template <typename TT> bool TryEnqueue(TT&& value, ui64 tag) { for (size_t i = 0; i < Concurrency; ++i) { @@ -307,22 +307,22 @@ namespace NThreading { AtomicUnlock(&queue.WriteLock); return true; } - } + } return false; - } - + } + TEntry* PrepareRead(size_t& index) { TEntry* entry = nullptr; ui64 tag = Max(); - + for (size_t i = 0; i < Concurrency; ++i) { - TEntry* e = Queues[i].PrepareRead(); - if (e && e->Tag < tag) { - index = i; - entry = e; - tag = e->Tag; - } - } + TEntry* e = Queues[i].PrepareRead(); + if (e && e->Tag < tag) { + index = i; + entry = e; + tag = e->Tag; + } + } if (entry) { // need second pass to catch updates within already scanned range @@ -338,91 +338,91 @@ namespace NThreading { } return entry; - } + } }; - + //////////////////////////////////////////////////////////////////////////////// // Concurrent many-many queue with strong FIFO guaranties. // Writers will not block readers (and vice versa), but will block each other. - + template <typename T, size_t ChunkSize = PLATFORM_PAGE_SIZE, typename TLock = TAdaptiveLock> class TManyManyQueue: private TNonCopyable { private: TPadded<TLock> WriteLock; TPadded<TLock> ReadLock; - + TOneOneQueue<T, ChunkSize> Queue; - + public: using TItem = T; - + template <typename TT> void Enqueue(TT&& value) { with_lock (WriteLock) { Queue.Enqueue(std::forward<TT>(value)); } - } - + } + bool Dequeue(T& value) { with_lock (ReadLock) { return Queue.Dequeue(value); } - } - + } + bool IsEmpty() { with_lock (ReadLock) { return Queue.IsEmpty(); } - } + } }; - + //////////////////////////////////////////////////////////////////////////////// // Multiple producers/single consumer partitioned queue. // Because of random partitioning reordering possible - FIFO not guaranteed! - + template <typename T, size_t Concurrency = 4, size_t ChunkSize = PLATFORM_PAGE_SIZE> class TRelaxedManyOneQueue: private TNonCopyable { struct TQueueType: public TOneOneQueue<T, ChunkSize> { TAtomic WriteLock = 0; }; - + private: union { size_t ReadPos = 0; char Pad[PLATFORM_CACHE_LINE]; }; - + TQueueType Queues[Concurrency]; - + public: using TItem = T; - + template <typename TT> void Enqueue(TT&& value) { while (!TryEnqueue(std::forward<TT>(value))) { SpinLockPause(); } - } - + } + bool Dequeue(T& value) { for (size_t i = 0; i < Concurrency; ++i) { TQueueType& queue = Queues[ReadPos++ % Concurrency]; if (queue.Dequeue(value)) { return true; } - } + } return false; - } - + } + bool IsEmpty() { for (size_t i = 0; i < Concurrency; ++i) { if (!Queues[i].IsEmpty()) { return false; } - } + } return true; - } - + } + private: template <typename TT> bool TryEnqueue(TT&& value) { @@ -434,15 +434,15 @@ namespace NThreading { AtomicUnlock(&queue.WriteLock); return true; } - } + } return false; - } + } }; - + //////////////////////////////////////////////////////////////////////////////// // Concurrent many-many partitioned queue. // Because of random partitioning reordering possible - FIFO not guaranteed! - + template <typename T, size_t Concurrency = 4, size_t ChunkSize = PLATFORM_PAGE_SIZE> class TRelaxedManyManyQueue: private TNonCopyable { struct TQueueType: public TOneOneQueue<T, ChunkSize> { @@ -454,21 +454,21 @@ namespace NThreading { TAtomic ReadLock = 0; char Pad2[PLATFORM_CACHE_LINE]; }; - }; - + }; + private: TQueueType Queues[Concurrency]; - + public: using TItem = T; - + template <typename TT> void Enqueue(TT&& value) { while (!TryEnqueue(std::forward<TT>(value))) { SpinLockPause(); } - } - + } + bool Dequeue(T& value) { size_t readPos = GetCycleCount(); for (size_t i = 0; i < Concurrency; ++i) { @@ -479,11 +479,11 @@ namespace NThreading { if (dequeued) { return true; } - } - } + } + } return false; - } - + } + bool IsEmpty() { for (size_t i = 0; i < Concurrency; ++i) { TQueueType& queue = Queues[i]; @@ -493,11 +493,11 @@ namespace NThreading { if (!empty) { return false; } - } - } + } + } return true; - } - + } + private: template <typename TT> bool TryEnqueue(TT&& value) { @@ -509,34 +509,34 @@ namespace NThreading { AtomicUnlock(&queue.WriteLock); return true; } - } + } return false; - } + } }; - + //////////////////////////////////////////////////////////////////////////////// // Simple wrapper to deal with AutoPtrs - + template <typename T, typename TImpl> class TAutoQueueBase: private TNonCopyable { private: TImpl Impl; - + public: using TItem = TAutoPtr<T>; - + ~TAutoQueueBase() { TAutoPtr<T> value; while (Dequeue(value)) { // do nothing } - } - + } + void Enqueue(TAutoPtr<T> value) { Impl.Enqueue(value.Get()); Y_UNUSED(value.Release()); } - + bool Dequeue(TAutoPtr<T>& value) { T* ptr = nullptr; if (Impl.Dequeue(ptr)) { @@ -544,25 +544,25 @@ namespace NThreading { return true; } return false; - } - + } + bool IsEmpty() { return Impl.IsEmpty(); } }; - + template <typename T, size_t ChunkSize = PLATFORM_PAGE_SIZE> using TAutoOneOneQueue = TAutoQueueBase<T, TOneOneQueue<T*, ChunkSize>>; - + template <typename T, size_t Concurrency = 4, size_t ChunkSize = PLATFORM_PAGE_SIZE> using TAutoManyOneQueue = TAutoQueueBase<T, TManyOneQueue<T*, Concurrency, ChunkSize>>; - + template <typename T, size_t ChunkSize = PLATFORM_PAGE_SIZE, typename TLock = TAdaptiveLock> using TAutoManyManyQueue = TAutoQueueBase<T, TManyManyQueue<T*, ChunkSize, TLock>>; - + template <typename T, size_t Concurrency = 4, size_t ChunkSize = PLATFORM_PAGE_SIZE> using TAutoRelaxedManyOneQueue = TAutoQueueBase<T, TRelaxedManyOneQueue<T*, Concurrency, ChunkSize>>; - + template <typename T, size_t Concurrency = 4, size_t ChunkSize = PLATFORM_PAGE_SIZE> using TAutoRelaxedManyManyQueue = TAutoQueueBase<T, TRelaxedManyManyQueue<T*, Concurrency, ChunkSize>>; } diff --git a/library/cpp/threading/chunk_queue/queue_ut.cpp b/library/cpp/threading/chunk_queue/queue_ut.cpp index dc103202e8..8cb36d8dd1 100644 --- a/library/cpp/threading/chunk_queue/queue_ut.cpp +++ b/library/cpp/threading/chunk_queue/queue_ut.cpp @@ -1,202 +1,202 @@ -#include "queue.h" - +#include "queue.h" + #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/set.h> - -namespace NThreading { + +#include <util/generic/set.h> + +namespace NThreading { //////////////////////////////////////////////////////////////////////////////// - + Y_UNIT_TEST_SUITE(TOneOneQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ TOneOneQueue<int> queue; - + int result = 0; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } - + Y_UNIT_TEST(ShouldReturnEntries) { TOneOneQueue<int> queue; queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); - + int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 1); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 2); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 3); - + UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } - + Y_UNIT_TEST(ShouldStoreMultipleChunks) { TOneOneQueue<int, 100> queue; for (int i = 0; i < 1000; ++i) { queue.Enqueue(i); - } - + } + for (int i = 0; i < 1000; ++i) { int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, i); - } + } } } ; - -//////////////////////////////////////////////////////////////////////////////// - + +//////////////////////////////////////////////////////////////////////////////// + Y_UNIT_TEST_SUITE(TManyOneQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ - TManyOneQueue<int> queue; - + TManyOneQueue<int> queue; + int result; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } - + Y_UNIT_TEST(ShouldReturnEntries) { TManyOneQueue<int> queue; queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); - + int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 1); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 2); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 3); - + UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } } ; - -//////////////////////////////////////////////////////////////////////////////// - + +//////////////////////////////////////////////////////////////////////////////// + Y_UNIT_TEST_SUITE(TManyManyQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ - TManyManyQueue<int> queue; - + TManyManyQueue<int> queue; + int result = 0; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } - + Y_UNIT_TEST(ShouldReturnEntries) { TManyManyQueue<int> queue; queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); - + int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 1); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 2); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 3); - + UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } } ; - -//////////////////////////////////////////////////////////////////////////////// - + +//////////////////////////////////////////////////////////////////////////////// + Y_UNIT_TEST_SUITE(TRelaxedManyOneQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ - TRelaxedManyOneQueue<int> queue; - + TRelaxedManyOneQueue<int> queue; + int result; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } - + Y_UNIT_TEST(ShouldReturnEntries) { TSet<int> items = {1, 2, 3}; - + TRelaxedManyOneQueue<int> queue; for (int item : items) { queue.Enqueue(item); } - + int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); - + UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } } ; - -//////////////////////////////////////////////////////////////////////////////// - + +//////////////////////////////////////////////////////////////////////////////// + Y_UNIT_TEST_SUITE(TRelaxedManyManyQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ - TRelaxedManyManyQueue<int> queue; - + TRelaxedManyManyQueue<int> queue; + int result = 0; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } - + Y_UNIT_TEST(ShouldReturnEntries) { TSet<int> items = {1, 2, 3}; - + TRelaxedManyManyQueue<int> queue; for (int item : items) { queue.Enqueue(item); } - + int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); - + UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); - + UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } diff --git a/library/cpp/threading/chunk_queue/readme.txt b/library/cpp/threading/chunk_queue/readme.txt index 104a8ec744..7c9f046a86 100644 --- a/library/cpp/threading/chunk_queue/readme.txt +++ b/library/cpp/threading/chunk_queue/readme.txt @@ -1,60 +1,60 @@ -vskipin@dev-kiwi09:~$ ./rtmr-queue-perf -w 4 -r 4 AdaptiveLock64 Mutex64 LFManyMany64 FastLFManyMany64 LFManyOne64 FastLFManyOne64 ManyMany64 ManyOne64 -2016-05-08T11:49:56.729254Z INFO: [-i] Iterations: 10000000 -2016-05-08T11:49:56.729319Z INFO: [-r] NumReaders: 4 -2016-05-08T11:49:56.729355Z INFO: [-w] NumWriters: 4 -2016-05-08T11:49:56.729502Z INFO: starting consumers... -2016-05-08T11:49:56.729621Z INFO: starting producers... -2016-05-08T11:49:56.729711Z INFO: wait for producers... -2016-05-08T11:50:14.650803Z INFO: wait for consumers... -2016-05-08T11:50:14.650859Z INFO: average producer time: 15.96846675 seconds -2016-05-08T11:50:14.650885Z INFO: average consumer time: 17.9209995 seconds -2016-05-08T11:50:14.650897Z INFO: test AdaptiveLock64 duration: 17.921395s (0.448034875us per iteration) -2016-05-08T11:50:14.650913Z INFO: starting consumers... -2016-05-08T11:50:14.651028Z INFO: starting producers... -2016-05-08T11:50:14.651122Z INFO: wait for producers... -2016-05-08T11:50:31.426378Z INFO: wait for consumers... -2016-05-08T11:50:31.426447Z INFO: average producer time: 15.58770475 seconds -2016-05-08T11:50:31.426491Z INFO: average consumer time: 16.775301 seconds -2016-05-08T11:50:31.426527Z INFO: test Mutex64 duration: 16.775614s (0.41939035us per iteration) -2016-05-08T11:50:31.426584Z INFO: starting consumers... -2016-05-08T11:50:31.426655Z INFO: starting producers... -2016-05-08T11:50:31.426749Z INFO: wait for producers... -2016-05-08T11:50:40.578425Z INFO: wait for consumers... -2016-05-08T11:50:40.578523Z INFO: average producer time: 8.69236075 seconds -2016-05-08T11:50:40.578577Z INFO: average consumer time: 9.15165125 seconds -2016-05-08T11:50:40.578617Z INFO: test LFManyMany64 duration: 9.152033s (0.228800825us per iteration) -2016-05-08T11:50:40.578670Z INFO: starting consumers... -2016-05-08T11:50:40.578742Z INFO: starting producers... -2016-05-08T11:50:40.578893Z INFO: wait for producers... -2016-05-08T11:50:47.447686Z INFO: wait for consumers... -2016-05-08T11:50:47.447758Z INFO: average producer time: 6.81136025 seconds -2016-05-08T11:50:47.447793Z INFO: average consumer time: 6.86875825 seconds -2016-05-08T11:50:47.447834Z INFO: test FastLFManyMany64 duration: 6.869165s (0.171729125us per iteration) -2016-05-08T11:50:47.447901Z INFO: starting consumers... -2016-05-08T11:50:47.447967Z INFO: starting producers... -2016-05-08T11:50:47.448058Z INFO: wait for producers... -2016-05-08T11:50:50.469710Z INFO: wait for consumers... -2016-05-08T11:50:50.469798Z INFO: average producer time: 2.9915505 seconds -2016-05-08T11:50:50.469848Z INFO: average consumer time: 3.02161675 seconds -2016-05-08T11:50:50.469883Z INFO: test LFManyOne64 duration: 3.021983s (0.075549575us per iteration) -2016-05-08T11:50:50.469947Z INFO: starting consumers... -2016-05-08T11:50:50.470012Z INFO: starting producers... -2016-05-08T11:50:50.470104Z INFO: wait for producers... -2016-05-08T11:50:53.139964Z INFO: wait for consumers... -2016-05-08T11:50:53.140050Z INFO: average producer time: 2.5656465 seconds -2016-05-08T11:50:53.140102Z INFO: average consumer time: 2.6697755 seconds -2016-05-08T11:50:53.140149Z INFO: test FastLFManyOne64 duration: 2.670202s (0.06675505us per iteration) -2016-05-08T11:50:53.140206Z INFO: starting consumers... -2016-05-08T11:50:53.140281Z INFO: starting producers... -2016-05-08T11:50:53.140371Z INFO: wait for producers... -2016-05-08T11:50:59.067812Z INFO: wait for consumers... -2016-05-08T11:50:59.067895Z INFO: average producer time: 5.8925505 seconds -2016-05-08T11:50:59.067946Z INFO: average consumer time: 5.9273365 seconds -2016-05-08T11:50:59.067978Z INFO: test ManyMany64 duration: 5.927773s (0.148194325us per iteration) -2016-05-08T11:50:59.068068Z INFO: starting consumers... -2016-05-08T11:50:59.068179Z INFO: starting producers... -2016-05-08T11:50:59.068288Z INFO: wait for producers... -2016-05-08T11:51:03.427416Z INFO: wait for consumers... -2016-05-08T11:51:03.427514Z INFO: average producer time: 4.1055505 seconds -2016-05-08T11:51:03.427560Z INFO: average consumer time: 4.35914975 seconds -2016-05-08T11:51:03.427596Z INFO: test ManyOne64 duration: 4.359529s (0.108988225us per iteration) +vskipin@dev-kiwi09:~$ ./rtmr-queue-perf -w 4 -r 4 AdaptiveLock64 Mutex64 LFManyMany64 FastLFManyMany64 LFManyOne64 FastLFManyOne64 ManyMany64 ManyOne64 +2016-05-08T11:49:56.729254Z INFO: [-i] Iterations: 10000000 +2016-05-08T11:49:56.729319Z INFO: [-r] NumReaders: 4 +2016-05-08T11:49:56.729355Z INFO: [-w] NumWriters: 4 +2016-05-08T11:49:56.729502Z INFO: starting consumers... +2016-05-08T11:49:56.729621Z INFO: starting producers... +2016-05-08T11:49:56.729711Z INFO: wait for producers... +2016-05-08T11:50:14.650803Z INFO: wait for consumers... +2016-05-08T11:50:14.650859Z INFO: average producer time: 15.96846675 seconds +2016-05-08T11:50:14.650885Z INFO: average consumer time: 17.9209995 seconds +2016-05-08T11:50:14.650897Z INFO: test AdaptiveLock64 duration: 17.921395s (0.448034875us per iteration) +2016-05-08T11:50:14.650913Z INFO: starting consumers... +2016-05-08T11:50:14.651028Z INFO: starting producers... +2016-05-08T11:50:14.651122Z INFO: wait for producers... +2016-05-08T11:50:31.426378Z INFO: wait for consumers... +2016-05-08T11:50:31.426447Z INFO: average producer time: 15.58770475 seconds +2016-05-08T11:50:31.426491Z INFO: average consumer time: 16.775301 seconds +2016-05-08T11:50:31.426527Z INFO: test Mutex64 duration: 16.775614s (0.41939035us per iteration) +2016-05-08T11:50:31.426584Z INFO: starting consumers... +2016-05-08T11:50:31.426655Z INFO: starting producers... +2016-05-08T11:50:31.426749Z INFO: wait for producers... +2016-05-08T11:50:40.578425Z INFO: wait for consumers... +2016-05-08T11:50:40.578523Z INFO: average producer time: 8.69236075 seconds +2016-05-08T11:50:40.578577Z INFO: average consumer time: 9.15165125 seconds +2016-05-08T11:50:40.578617Z INFO: test LFManyMany64 duration: 9.152033s (0.228800825us per iteration) +2016-05-08T11:50:40.578670Z INFO: starting consumers... +2016-05-08T11:50:40.578742Z INFO: starting producers... +2016-05-08T11:50:40.578893Z INFO: wait for producers... +2016-05-08T11:50:47.447686Z INFO: wait for consumers... +2016-05-08T11:50:47.447758Z INFO: average producer time: 6.81136025 seconds +2016-05-08T11:50:47.447793Z INFO: average consumer time: 6.86875825 seconds +2016-05-08T11:50:47.447834Z INFO: test FastLFManyMany64 duration: 6.869165s (0.171729125us per iteration) +2016-05-08T11:50:47.447901Z INFO: starting consumers... +2016-05-08T11:50:47.447967Z INFO: starting producers... +2016-05-08T11:50:47.448058Z INFO: wait for producers... +2016-05-08T11:50:50.469710Z INFO: wait for consumers... +2016-05-08T11:50:50.469798Z INFO: average producer time: 2.9915505 seconds +2016-05-08T11:50:50.469848Z INFO: average consumer time: 3.02161675 seconds +2016-05-08T11:50:50.469883Z INFO: test LFManyOne64 duration: 3.021983s (0.075549575us per iteration) +2016-05-08T11:50:50.469947Z INFO: starting consumers... +2016-05-08T11:50:50.470012Z INFO: starting producers... +2016-05-08T11:50:50.470104Z INFO: wait for producers... +2016-05-08T11:50:53.139964Z INFO: wait for consumers... +2016-05-08T11:50:53.140050Z INFO: average producer time: 2.5656465 seconds +2016-05-08T11:50:53.140102Z INFO: average consumer time: 2.6697755 seconds +2016-05-08T11:50:53.140149Z INFO: test FastLFManyOne64 duration: 2.670202s (0.06675505us per iteration) +2016-05-08T11:50:53.140206Z INFO: starting consumers... +2016-05-08T11:50:53.140281Z INFO: starting producers... +2016-05-08T11:50:53.140371Z INFO: wait for producers... +2016-05-08T11:50:59.067812Z INFO: wait for consumers... +2016-05-08T11:50:59.067895Z INFO: average producer time: 5.8925505 seconds +2016-05-08T11:50:59.067946Z INFO: average consumer time: 5.9273365 seconds +2016-05-08T11:50:59.067978Z INFO: test ManyMany64 duration: 5.927773s (0.148194325us per iteration) +2016-05-08T11:50:59.068068Z INFO: starting consumers... +2016-05-08T11:50:59.068179Z INFO: starting producers... +2016-05-08T11:50:59.068288Z INFO: wait for producers... +2016-05-08T11:51:03.427416Z INFO: wait for consumers... +2016-05-08T11:51:03.427514Z INFO: average producer time: 4.1055505 seconds +2016-05-08T11:51:03.427560Z INFO: average consumer time: 4.35914975 seconds +2016-05-08T11:51:03.427596Z INFO: test ManyOne64 duration: 4.359529s (0.108988225us per iteration) diff --git a/library/cpp/threading/chunk_queue/ut/ya.make b/library/cpp/threading/chunk_queue/ut/ya.make index d69e219f66..a35ed6bc4b 100644 --- a/library/cpp/threading/chunk_queue/ut/ya.make +++ b/library/cpp/threading/chunk_queue/ut/ya.make @@ -1,9 +1,9 @@ UNITTEST_FOR(library/cpp/threading/chunk_queue) - + OWNER(g:rtmr) - -SRCS( - queue_ut.cpp -) - -END() + +SRCS( + queue_ut.cpp +) + +END() diff --git a/library/cpp/threading/chunk_queue/ya.make b/library/cpp/threading/chunk_queue/ya.make index 7e6ead7b36..2f883140ba 100644 --- a/library/cpp/threading/chunk_queue/ya.make +++ b/library/cpp/threading/chunk_queue/ya.make @@ -1,9 +1,9 @@ -LIBRARY() - +LIBRARY() + OWNER(g:rtmr) - -SRCS( - queue.cpp -) - -END() + +SRCS( + queue.cpp +) + +END() diff --git a/library/cpp/threading/future/core/future-inl.h b/library/cpp/threading/future/core/future-inl.h index a72985ec47..5fd4296a93 100644 --- a/library/cpp/threading/future/core/future-inl.h +++ b/library/cpp/threading/future/core/future-inl.h @@ -1,21 +1,21 @@ -#pragma once - -#if !defined(INCLUDE_FUTURE_INL_H) -#error "you should never include future-inl.h directly" +#pragma once + +#if !defined(INCLUDE_FUTURE_INL_H) +#error "you should never include future-inl.h directly" #endif // INCLUDE_FUTURE_INL_H - + namespace NThreading { namespace NImpl { //////////////////////////////////////////////////////////////////////////////// - + template <typename T> using TCallback = std::function<void(const TFuture<T>&)>; - + template <typename T> using TCallbackList = TVector<TCallback<T>>; // TODO: small vector - + //////////////////////////////////////////////////////////////////////////////// - + enum class TError { Error }; @@ -29,28 +29,28 @@ namespace NThreading { ValueSet, ValueRead, }; - + private: mutable TAtomic State; TAdaptiveLock StateLock; - + TCallbackList<T> Callbacks; mutable THolder<TSystemEvent> ReadyEvent; - + std::exception_ptr Exception; - + union { char NullValue; T Value; }; - + void AccessValue(TDuration timeout, int acquireState) const { int state = AtomicGet(State); if (Y_UNLIKELY(state == NotReady)) { if (timeout == TDuration::Zero()) { ythrow TFutureException() << "value not set"; } - + if (!Wait(timeout)) { ythrow TFutureException() << "wait timeout"; } @@ -114,17 +114,17 @@ namespace NThreading { bool HasException() const { return AtomicGet(State) == ExceptionSet; } - + const T& GetValue(TDuration timeout = TDuration::Zero()) const { AccessValue(timeout, ValueRead); return Value; } - + T ExtractValue(TDuration timeout = TDuration::Zero()) { AccessValue(timeout, ValueMoved); return std::move(Value); } - + template <typename TT> void SetValue(TT&& value) { bool success = TrySetValue(std::forward<TT>(value)); @@ -137,21 +137,21 @@ namespace NThreading { bool TrySetValue(TT&& value) { TSystemEvent* readyEvent = nullptr; TCallbackList<T> callbacks; - + with_lock (StateLock) { int state = AtomicGet(State); if (Y_UNLIKELY(state != NotReady)) { return false; } - + new (&Value) T(std::forward<TT>(value)); - + readyEvent = ReadyEvent.Get(); callbacks = std::move(Callbacks); AtomicSet(State, ValueSet); } - + if (readyEvent) { readyEvent->Signal(); } @@ -164,8 +164,8 @@ namespace NThreading { } return true; - } - + } + void SetException(std::exception_ptr e) { bool success = TrySetException(std::move(e)); if (Y_UNLIKELY(!success)) { @@ -176,18 +176,18 @@ namespace NThreading { bool TrySetException(std::exception_ptr e) { TSystemEvent* readyEvent; TCallbackList<T> callbacks; - + with_lock (StateLock) { int state = AtomicGet(State); if (Y_UNLIKELY(state != NotReady)) { return false; } - + Exception = std::move(e); - + readyEvent = ReadyEvent.Get(); callbacks = std::move(Callbacks); - + AtomicSet(State, ExceptionSet); } @@ -203,8 +203,8 @@ namespace NThreading { } return true; - } - + } + template <typename F> bool Subscribe(F&& func) { with_lock (StateLock) { @@ -216,33 +216,33 @@ namespace NThreading { } return false; } - + void Wait() const { Wait(TInstant::Max()); - } - + } + bool Wait(TDuration timeout) const { return Wait(timeout.ToDeadLine()); } - + bool Wait(TInstant deadline) const { TSystemEvent* readyEvent = nullptr; - + with_lock (StateLock) { int state = AtomicGet(State); if (state != NotReady) { return true; } - + if (!ReadyEvent) { ReadyEvent.Reset(new TSystemEvent()); } readyEvent = ReadyEvent.Get(); } - + Y_ASSERT(readyEvent); return readyEvent->WaitD(deadline); - } + } void TryRethrowWithState(int state) const { if (Y_UNLIKELY(state == ExceptionSet)) { @@ -251,9 +251,9 @@ namespace NThreading { } } }; - + //////////////////////////////////////////////////////////////////////////////// - + template <> class TFutureState<void>: public TAtomicRefCount<TFutureState<void>> { enum { @@ -261,22 +261,22 @@ namespace NThreading { ValueSet, ExceptionSet, }; - + private: TAtomic State; TAdaptiveLock StateLock; - + TCallbackList<void> Callbacks; mutable THolder<TSystemEvent> ReadyEvent; - + std::exception_ptr Exception; public: TFutureState(bool valueSet = false) : State(valueSet ? ValueSet : NotReady) { - } - + } + TFutureState(std::exception_ptr exception, TError) : State(ExceptionSet) , Exception(std::move(exception)) @@ -285,8 +285,8 @@ namespace NThreading { bool HasValue() const { return AtomicGet(State) == ValueSet; - } - + } + void TryRethrow() const { int state = AtomicGet(State); TryRethrowWithState(state); @@ -295,26 +295,26 @@ namespace NThreading { bool HasException() const { return AtomicGet(State) == ExceptionSet; } - + void GetValue(TDuration timeout = TDuration::Zero()) const { int state = AtomicGet(State); if (Y_UNLIKELY(state == NotReady)) { if (timeout == TDuration::Zero()) { ythrow TFutureException() << "value not set"; } - + if (!Wait(timeout)) { ythrow TFutureException() << "wait timeout"; } - + state = AtomicGet(State); } - + TryRethrowWithState(state); - + Y_ASSERT(state == ValueSet); } - + void SetValue() { bool success = TrySetValue(); if (Y_UNLIKELY(!success)) { @@ -325,19 +325,19 @@ namespace NThreading { bool TrySetValue() { TSystemEvent* readyEvent = nullptr; TCallbackList<void> callbacks; - + with_lock (StateLock) { int state = AtomicGet(State); if (Y_UNLIKELY(state != NotReady)) { return false; } - + readyEvent = ReadyEvent.Get(); callbacks = std::move(Callbacks); - + AtomicSet(State, ValueSet); } - + if (readyEvent) { readyEvent->Signal(); } @@ -350,8 +350,8 @@ namespace NThreading { } return true; - } - + } + void SetException(std::exception_ptr e) { bool success = TrySetException(std::move(e)); if (Y_UNLIKELY(!success)) { @@ -362,25 +362,25 @@ namespace NThreading { bool TrySetException(std::exception_ptr e) { TSystemEvent* readyEvent = nullptr; TCallbackList<void> callbacks; - + with_lock (StateLock) { int state = AtomicGet(State); if (Y_UNLIKELY(state != NotReady)) { return false; } - + Exception = std::move(e); - + readyEvent = ReadyEvent.Get(); callbacks = std::move(Callbacks); - + AtomicSet(State, ExceptionSet); } - + if (readyEvent) { readyEvent->Signal(); } - + if (callbacks) { TFuture<void> temp(this); for (auto& callback : callbacks) { @@ -390,7 +390,7 @@ namespace NThreading { return true; } - + template <typename F> bool Subscribe(F&& func) { with_lock (StateLock) { @@ -402,15 +402,15 @@ namespace NThreading { } return false; } - + void Wait() const { Wait(TInstant::Max()); - } - + } + bool Wait(TDuration timeout) const { return Wait(timeout.ToDeadLine()); } - + bool Wait(TInstant deadline) const { TSystemEvent* readyEvent = nullptr; @@ -428,7 +428,7 @@ namespace NThreading { Y_ASSERT(readyEvent); return readyEvent->WaitD(deadline); - } + } void TryRethrowWithState(int state) const { if (Y_UNLIKELY(state == ExceptionSet)) { @@ -437,19 +437,19 @@ namespace NThreading { } } }; - + //////////////////////////////////////////////////////////////////////////////// - + template <typename T> inline void SetValueImpl(TPromise<T>& promise, const T& value) { promise.SetValue(value); } - + template <typename T> inline void SetValueImpl(TPromise<T>& promise, T&& value) { promise.SetValue(std::move(value)); - } - + } + template <typename T> inline void SetValueImpl(TPromise<T>& promise, const TFuture<T>& future, std::enable_if_t<!std::is_void<T>::value, bool> = false) { @@ -463,8 +463,8 @@ namespace NThreading { } promise.SetValue(*value); }); - } - + } + template <typename T> inline void SetValueImpl(TPromise<void>& promise, const TFuture<T>& future) { future.Subscribe([=](const TFuture<T>& f) mutable { @@ -487,9 +487,9 @@ namespace NThreading { if (Y_UNLIKELY(!success)) { throw; } - } - } - + } + } + template <typename F> inline void SetValue(TPromise<void>& promise, F&& func, std::enable_if_t<std::is_void<TFunctionResult<F>>::value, bool> = false) { @@ -498,14 +498,14 @@ namespace NThreading { } catch (...) { promise.SetException(std::current_exception()); return; - } + } promise.SetValue(); - } - + } + } - + //////////////////////////////////////////////////////////////////////////////// - + class TFutureStateId { private: const void* Id; @@ -535,41 +535,41 @@ namespace NThreading { template <typename T> inline TFuture<T>::TFuture(const TIntrusivePtr<TFutureState>& state) noexcept : State(state) - { - } - + { + } + template <typename T> inline void TFuture<T>::Swap(TFuture<T>& other) { State.Swap(other.State); } - + template <typename T> inline bool TFuture<T>::HasValue() const { return State && State->HasValue(); } - + template <typename T> inline const T& TFuture<T>::GetValue(TDuration timeout) const { EnsureInitialized(); return State->GetValue(timeout); - } - + } + template <typename T> inline T TFuture<T>::ExtractValue(TDuration timeout) { EnsureInitialized(); return State->ExtractValue(timeout); } - + template <typename T> inline const T& TFuture<T>::GetValueSync() const { return GetValue(TDuration::Max()); } - + template <typename T> inline T TFuture<T>::ExtractValueSync() { return ExtractValue(TDuration::Max()); } - + template <typename T> inline void TFuture<T>::TryRethrow() const { if (State) { @@ -581,25 +581,25 @@ namespace NThreading { inline bool TFuture<T>::HasException() const { return State && State->HasException(); } - + template <typename T> inline void TFuture<T>::Wait() const { EnsureInitialized(); return State->Wait(); } - + template <typename T> inline bool TFuture<T>::Wait(TDuration timeout) const { EnsureInitialized(); return State->Wait(timeout); } - + template <typename T> inline bool TFuture<T>::Wait(TInstant deadline) const { EnsureInitialized(); return State->Wait(deadline); } - + template <typename T> template <typename F> inline const TFuture<T>& TFuture<T>::Subscribe(F&& func) const { @@ -609,7 +609,7 @@ namespace NThreading { } return *this; } - + template <typename T> template <typename F> inline const TFuture<T>& TFuture<T>::NoexceptSubscribe(F&& func) const noexcept { @@ -626,7 +626,7 @@ namespace NThreading { }); return promise; } - + template <typename T> inline TFuture<void> TFuture<T>::IgnoreResult() const { auto promise = NewPromise(); @@ -639,8 +639,8 @@ namespace NThreading { template <typename T> inline bool TFuture<T>::Initialized() const { return bool(State); - } - + } + template <typename T> inline TMaybe<TFutureStateId> TFuture<T>::StateId() const noexcept { return State != nullptr ? MakeMaybe<TFutureStateId>(*State) : Nothing(); @@ -650,33 +650,33 @@ namespace NThreading { inline void TFuture<T>::EnsureInitialized() const { if (!State) { ythrow TFutureException() << "state not initialized"; - } + } } - + //////////////////////////////////////////////////////////////////////////////// - + inline TFuture<void>::TFuture(const TIntrusivePtr<TFutureState>& state) noexcept : State(state) { } - + inline void TFuture<void>::Swap(TFuture<void>& other) { State.Swap(other.State); } - + inline bool TFuture<void>::HasValue() const { return State && State->HasValue(); } - + inline void TFuture<void>::GetValue(TDuration timeout) const { EnsureInitialized(); State->GetValue(timeout); } - + inline void TFuture<void>::GetValueSync() const { GetValue(TDuration::Max()); } - + inline void TFuture<void>::TryRethrow() const { if (State) { State->TryRethrow(); @@ -686,7 +686,7 @@ namespace NThreading { inline bool TFuture<void>::HasException() const { return State && State->HasException(); } - + inline void TFuture<void>::Wait() const { EnsureInitialized(); return State->Wait(); @@ -696,12 +696,12 @@ namespace NThreading { EnsureInitialized(); return State->Wait(timeout); } - + inline bool TFuture<void>::Wait(TInstant deadline) const { EnsureInitialized(); return State->Wait(deadline); } - + template <typename F> inline const TFuture<void>& TFuture<void>::Subscribe(F&& func) const { EnsureInitialized(); @@ -710,7 +710,7 @@ namespace NThreading { } return *this; } - + template <typename F> inline const TFuture<void>& TFuture<void>::NoexceptSubscribe(F&& func) const noexcept { return Subscribe(std::forward<F>(func)); @@ -725,7 +725,7 @@ namespace NThreading { }); return promise; } - + template <typename R> inline TFuture<R> TFuture<void>::Return(const R& value) const { auto promise = NewPromise<R>(); @@ -739,12 +739,12 @@ namespace NThreading { promise.SetValue(value); }); return promise; - } - + } + inline bool TFuture<void>::Initialized() const { return bool(State); } - + inline TMaybe<TFutureStateId> TFuture<void>::StateId() const noexcept { return State != nullptr ? MakeMaybe<TFutureStateId>(*State) : Nothing(); } @@ -752,39 +752,39 @@ namespace NThreading { inline void TFuture<void>::EnsureInitialized() const { if (!State) { ythrow TFutureException() << "state not initialized"; - } + } } - + //////////////////////////////////////////////////////////////////////////////// - + template <typename T> inline TPromise<T>::TPromise(const TIntrusivePtr<TFutureState>& state) noexcept : State(state) { } - + template <typename T> inline void TPromise<T>::Swap(TPromise<T>& other) { State.Swap(other.State); } - + template <typename T> inline const T& TPromise<T>::GetValue() const { EnsureInitialized(); return State->GetValue(); } - + template <typename T> inline T TPromise<T>::ExtractValue() { EnsureInitialized(); return State->ExtractValue(); } - + template <typename T> inline bool TPromise<T>::HasValue() const { return State && State->HasValue(); } - + template <typename T> inline void TPromise<T>::SetValue(const T& value) { EnsureInitialized(); @@ -796,7 +796,7 @@ namespace NThreading { EnsureInitialized(); State->SetValue(std::move(value)); } - + template <typename T> inline bool TPromise<T>::TrySetValue(const T& value) { EnsureInitialized(); @@ -820,19 +820,19 @@ namespace NThreading { inline bool TPromise<T>::HasException() const { return State && State->HasException(); } - + template <typename T> inline void TPromise<T>::SetException(const TString& e) { EnsureInitialized(); State->SetException(std::make_exception_ptr(yexception() << e)); } - + template <typename T> inline void TPromise<T>::SetException(std::exception_ptr e) { EnsureInitialized(); State->SetException(std::move(e)); } - + template <typename T> inline bool TPromise<T>::TrySetException(std::exception_ptr e) { EnsureInitialized(); @@ -844,49 +844,49 @@ namespace NThreading { EnsureInitialized(); return TFuture<T>(State); } - + template <typename T> inline TPromise<T>::operator TFuture<T>() const { return GetFuture(); } - + template <typename T> inline bool TPromise<T>::Initialized() const { return bool(State); } - + template <typename T> inline void TPromise<T>::EnsureInitialized() const { if (!State) { ythrow TFutureException() << "state not initialized"; } } - + //////////////////////////////////////////////////////////////////////////////// - + inline TPromise<void>::TPromise(const TIntrusivePtr<TFutureState>& state) noexcept : State(state) { } - + inline void TPromise<void>::Swap(TPromise<void>& other) { State.Swap(other.State); } - + inline void TPromise<void>::GetValue() const { EnsureInitialized(); State->GetValue(); } - + inline bool TPromise<void>::HasValue() const { return State && State->HasValue(); } - + inline void TPromise<void>::SetValue() { EnsureInitialized(); State->SetValue(); } - + inline bool TPromise<void>::TrySetValue() { EnsureInitialized(); return State->TrySetValue(); @@ -901,17 +901,17 @@ namespace NThreading { inline bool TPromise<void>::HasException() const { return State && State->HasException(); } - + inline void TPromise<void>::SetException(const TString& e) { EnsureInitialized(); State->SetException(std::make_exception_ptr(yexception() << e)); } - + inline void TPromise<void>::SetException(std::exception_ptr e) { EnsureInitialized(); State->SetException(std::move(e)); } - + inline bool TPromise<void>::TrySetException(std::exception_ptr e) { EnsureInitialized(); return State->TrySetException(std::move(e)); @@ -921,42 +921,42 @@ namespace NThreading { EnsureInitialized(); return TFuture<void>(State); } - + inline TPromise<void>::operator TFuture<void>() const { return GetFuture(); } - + inline bool TPromise<void>::Initialized() const { return bool(State); } - + inline void TPromise<void>::EnsureInitialized() const { if (!State) { ythrow TFutureException() << "state not initialized"; } } - + //////////////////////////////////////////////////////////////////////////////// - + template <typename T> inline TPromise<T> NewPromise() { return {new NImpl::TFutureState<T>()}; - } - + } + inline TPromise<void> NewPromise() { return {new NImpl::TFutureState<void>()}; } - + template <typename T> inline TFuture<T> MakeFuture(const T& value) { return {new NImpl::TFutureState<T>(value)}; } - + template <typename T> inline TFuture<std::remove_reference_t<T>> MakeFuture(T&& value) { return {new NImpl::TFutureState<std::remove_reference_t<T>>(std::forward<T>(value))}; } - + template <typename T> inline TFuture<T> MakeFuture() { struct TCache { @@ -970,7 +970,7 @@ namespace NThreading { }; return Singleton<TCache>()->Instance; } - + template <typename T> inline TFuture<T> MakeErrorFuture(std::exception_ptr exception) { @@ -983,4 +983,4 @@ namespace NThreading { }; return Singleton<TCache>()->Instance; } -} +} diff --git a/library/cpp/threading/future/core/future.cpp b/library/cpp/threading/future/core/future.cpp index 257a2a218f..3243afcb40 100644 --- a/library/cpp/threading/future/core/future.cpp +++ b/library/cpp/threading/future/core/future.cpp @@ -1 +1 @@ -#include "future.h" +#include "future.h" diff --git a/library/cpp/threading/future/core/future.h b/library/cpp/threading/future/core/future.h index 2dfc4e0f25..2e82bb953e 100644 --- a/library/cpp/threading/future/core/future.h +++ b/library/cpp/threading/future/core/future.h @@ -1,26 +1,26 @@ -#pragma once - +#pragma once + #include "fwd.h" -#include <util/datetime/base.h> -#include <util/generic/function.h> +#include <util/datetime/base.h> +#include <util/generic/function.h> #include <util/generic/maybe.h> -#include <util/generic/ptr.h> -#include <util/generic/vector.h> -#include <util/generic/yexception.h> -#include <util/system/event.h> -#include <util/system/spinlock.h> - +#include <util/generic/ptr.h> +#include <util/generic/vector.h> +#include <util/generic/yexception.h> +#include <util/system/event.h> +#include <util/system/spinlock.h> + namespace NThreading { //////////////////////////////////////////////////////////////////////////////// - + struct TFutureException: public yexception {}; - + // creates unset promise template <typename T> TPromise<T> NewPromise(); TPromise<void> NewPromise(); - + // creates preset future template <typename T> TFuture<T> MakeFuture(const T& value); @@ -31,18 +31,18 @@ namespace NThreading { template <typename T> TFuture<T> MakeErrorFuture(std::exception_ptr exception); TFuture<void> MakeFuture(); - + //////////////////////////////////////////////////////////////////////////////// - + namespace NImpl { template <typename T> class TFutureState; - + template <typename T> struct TFutureType { using TType = T; }; - + template <typename T> struct TFutureType<TFuture<T>> { using TType = typename TFutureType<T>::TType; @@ -54,10 +54,10 @@ namespace NThreading { using TType = decltype(std::declval<F&>()(std::declval<const TFuture<T>&>())); }; } - + template <typename F> using TFutureType = typename NImpl::TFutureType<F>::TType; - + template <typename F, typename T> using TFutureCallResult = typename NImpl::TFutureCallResult<F, T>::TType; @@ -65,14 +65,14 @@ namespace NThreading { class TFutureStateId; //////////////////////////////////////////////////////////////////////////////// - + template <typename T> class TFuture { using TFutureState = NImpl::TFutureState<T>; - + private: TIntrusivePtr<TFutureState> State; - + public: using value_type = T; @@ -80,29 +80,29 @@ namespace NThreading { TFuture(const TFuture<T>& other) noexcept = default; TFuture(TFuture<T>&& other) noexcept = default; TFuture(const TIntrusivePtr<TFutureState>& state) noexcept; - + TFuture<T>& operator=(const TFuture<T>& other) noexcept = default; TFuture<T>& operator=(TFuture<T>&& other) noexcept = default; void Swap(TFuture<T>& other); - + bool Initialized() const; - + bool HasValue() const; const T& GetValue(TDuration timeout = TDuration::Zero()) const; const T& GetValueSync() const; T ExtractValue(TDuration timeout = TDuration::Zero()); T ExtractValueSync(); - + void TryRethrow() const; bool HasException() const; - + void Wait() const; bool Wait(TDuration timeout) const; bool Wait(TInstant deadline) const; - + template <typename F> const TFuture<T>& Subscribe(F&& callback) const; - + // precondition: EnsureInitialized() passes // postcondition: std::terminate is highly unlikely template <typename F> @@ -110,9 +110,9 @@ namespace NThreading { template <typename F> TFuture<TFutureType<TFutureCallResult<F, T>>> Apply(F&& func) const; - + TFuture<void> IgnoreResult() const; - + //! If the future is initialized returns the future state identifier. Otherwise returns an empty optional /** The state identifier is guaranteed to be unique during the future state lifetime and could be reused after its death **/ @@ -120,16 +120,16 @@ namespace NThreading { void EnsureInitialized() const; }; - + //////////////////////////////////////////////////////////////////////////////// - + template <> class TFuture<void> { using TFutureState = NImpl::TFutureState<void>; - + private: TIntrusivePtr<TFutureState> State = nullptr; - + public: using value_type = void; @@ -137,27 +137,27 @@ namespace NThreading { TFuture(const TFuture<void>& other) noexcept = default; TFuture(TFuture<void>&& other) noexcept = default; TFuture(const TIntrusivePtr<TFutureState>& state) noexcept; - + TFuture<void>& operator=(const TFuture<void>& other) noexcept = default; TFuture<void>& operator=(TFuture<void>&& other) noexcept = default; void Swap(TFuture<void>& other); - + bool Initialized() const; - + bool HasValue() const; void GetValue(TDuration timeout = TDuration::Zero()) const; void GetValueSync() const; - + void TryRethrow() const; bool HasException() const; - + void Wait() const; bool Wait(TDuration timeout) const; bool Wait(TInstant deadline) const; - + template <typename F> const TFuture<void>& Subscribe(F&& callback) const; - + // precondition: EnsureInitialized() passes // postcondition: std::terminate is highly unlikely template <typename F> @@ -165,10 +165,10 @@ namespace NThreading { template <typename F> TFuture<TFutureType<TFutureCallResult<F, void>>> Apply(F&& func) const; - + template <typename R> TFuture<R> Return(const R& value) const; - + TFuture<void> IgnoreResult() const { return *this; } @@ -180,35 +180,35 @@ namespace NThreading { void EnsureInitialized() const; }; - + //////////////////////////////////////////////////////////////////////////////// - + template <typename T> class TPromise { using TFutureState = NImpl::TFutureState<T>; - + private: TIntrusivePtr<TFutureState> State = nullptr; - + public: TPromise() noexcept = default; TPromise(const TPromise<T>& other) noexcept = default; TPromise(TPromise<T>&& other) noexcept = default; TPromise(const TIntrusivePtr<TFutureState>& state) noexcept; - + TPromise<T>& operator=(const TPromise<T>& other) noexcept = default; TPromise<T>& operator=(TPromise<T>&& other) noexcept = default; void Swap(TPromise<T>& other); - + bool Initialized() const; - + bool HasValue() const; const T& GetValue() const; T ExtractValue(); - + void SetValue(const T& value); void SetValue(T&& value); - + bool TrySetValue(const T& value); bool TrySetValue(T&& value); @@ -217,56 +217,56 @@ namespace NThreading { void SetException(const TString& e); void SetException(std::exception_ptr e); bool TrySetException(std::exception_ptr e); - + TFuture<T> GetFuture() const; operator TFuture<T>() const; - + private: void EnsureInitialized() const; }; - + //////////////////////////////////////////////////////////////////////////////// - + template <> class TPromise<void> { using TFutureState = NImpl::TFutureState<void>; - + private: TIntrusivePtr<TFutureState> State; - + public: TPromise() noexcept = default; TPromise(const TPromise<void>& other) noexcept = default; TPromise(TPromise<void>&& other) noexcept = default; TPromise(const TIntrusivePtr<TFutureState>& state) noexcept; - + TPromise<void>& operator=(const TPromise<void>& other) noexcept = default; TPromise<void>& operator=(TPromise<void>&& other) noexcept = default; void Swap(TPromise<void>& other); - + bool Initialized() const; - + bool HasValue() const; void GetValue() const; - + void SetValue(); bool TrySetValue(); - + void TryRethrow() const; bool HasException() const; void SetException(const TString& e); void SetException(std::exception_ptr e); bool TrySetException(std::exception_ptr e); - + TFuture<void> GetFuture() const; operator TFuture<void>() const; - + private: void EnsureInitialized() const; }; - + } - -#define INCLUDE_FUTURE_INL_H -#include "future-inl.h" -#undef INCLUDE_FUTURE_INL_H + +#define INCLUDE_FUTURE_INL_H +#include "future-inl.h" +#undef INCLUDE_FUTURE_INL_H diff --git a/library/cpp/threading/future/future.h b/library/cpp/threading/future/future.h index 6b138a3583..35db9abbe2 100644 --- a/library/cpp/threading/future/future.h +++ b/library/cpp/threading/future/future.h @@ -1,4 +1,4 @@ -#pragma once - +#pragma once + #include "core/future.h" #include "wait/wait.h" diff --git a/library/cpp/threading/future/future_ut.cpp b/library/cpp/threading/future/future_ut.cpp index a9d5a6cfbd..05950a568d 100644 --- a/library/cpp/threading/future/future_ut.cpp +++ b/library/cpp/threading/future/future_ut.cpp @@ -1,7 +1,7 @@ -#include "future.h" - +#include "future.h" + #include <library/cpp/testing/unittest/registar.h> - + #include <list> #include <type_traits> @@ -63,168 +63,168 @@ namespace { } //////////////////////////////////////////////////////////////////////////////// - + Y_UNIT_TEST_SUITE(TFutureTest) { Y_UNIT_TEST(ShouldInitiallyHasNoValue) { TPromise<int> promise; UNIT_ASSERT(!promise.HasValue()); - + promise = NewPromise<int>(); UNIT_ASSERT(!promise.HasValue()); - + TFuture<int> future; UNIT_ASSERT(!future.HasValue()); - + future = promise.GetFuture(); UNIT_ASSERT(!future.HasValue()); } - + Y_UNIT_TEST(ShouldInitiallyHasNoValueVoid) { TPromise<void> promise; UNIT_ASSERT(!promise.HasValue()); - + promise = NewPromise(); UNIT_ASSERT(!promise.HasValue()); - + TFuture<void> future; UNIT_ASSERT(!future.HasValue()); - + future = promise.GetFuture(); UNIT_ASSERT(!future.HasValue()); } - + Y_UNIT_TEST(ShouldStoreValue) { TPromise<int> promise = NewPromise<int>(); promise.SetValue(123); UNIT_ASSERT(promise.HasValue()); UNIT_ASSERT_EQUAL(promise.GetValue(), 123); - + TFuture<int> future = promise.GetFuture(); UNIT_ASSERT(future.HasValue()); UNIT_ASSERT_EQUAL(future.GetValue(), 123); - + future = MakeFuture(345); UNIT_ASSERT(future.HasValue()); UNIT_ASSERT_EQUAL(future.GetValue(), 345); } - + Y_UNIT_TEST(ShouldStoreValueVoid) { TPromise<void> promise = NewPromise(); promise.SetValue(); UNIT_ASSERT(promise.HasValue()); - + TFuture<void> future = promise.GetFuture(); UNIT_ASSERT(future.HasValue()); - + future = MakeFuture(); UNIT_ASSERT(future.HasValue()); } - + struct TTestCallback { int Value; - + TTestCallback(int value) : Value(value) { } - + void Callback(const TFuture<int>& future) { Value += future.GetValue(); } - + int Func(const TFuture<int>& future) { return (Value += future.GetValue()); } - + void VoidFunc(const TFuture<int>& future) { future.GetValue(); } - + TFuture<int> FutureFunc(const TFuture<int>& future) { return MakeFuture(Value += future.GetValue()); } - + TPromise<void> Signal = NewPromise(); TFuture<void> FutureVoidFunc(const TFuture<int>& future) { future.GetValue(); return Signal; } }; - + Y_UNIT_TEST(ShouldInvokeCallback) { TPromise<int> promise = NewPromise<int>(); - + TTestCallback callback(123); TFuture<int> future = promise.GetFuture() .Subscribe([&](const TFuture<int>& theFuture) { return callback.Callback(theFuture); }); - + promise.SetValue(456); UNIT_ASSERT_EQUAL(future.GetValue(), 456); UNIT_ASSERT_EQUAL(callback.Value, 123 + 456); } - + Y_UNIT_TEST(ShouldApplyFunc) { TPromise<int> promise = NewPromise<int>(); - + TTestCallback callback(123); TFuture<int> future = promise.GetFuture() .Apply([&](const auto& theFuture) { return callback.Func(theFuture); }); - + promise.SetValue(456); UNIT_ASSERT_EQUAL(future.GetValue(), 123 + 456); UNIT_ASSERT_EQUAL(callback.Value, 123 + 456); } - + Y_UNIT_TEST(ShouldApplyVoidFunc) { TPromise<int> promise = NewPromise<int>(); - + TTestCallback callback(123); TFuture<void> future = promise.GetFuture() .Apply([&](const auto& theFuture) { return callback.VoidFunc(theFuture); }); - + promise.SetValue(456); UNIT_ASSERT(future.HasValue()); } - + Y_UNIT_TEST(ShouldApplyFutureFunc) { TPromise<int> promise = NewPromise<int>(); - + TTestCallback callback(123); TFuture<int> future = promise.GetFuture() .Apply([&](const auto& theFuture) { return callback.FutureFunc(theFuture); }); - + promise.SetValue(456); UNIT_ASSERT_EQUAL(future.GetValue(), 123 + 456); UNIT_ASSERT_EQUAL(callback.Value, 123 + 456); } - + Y_UNIT_TEST(ShouldApplyFutureVoidFunc) { TPromise<int> promise = NewPromise<int>(); - + TTestCallback callback(123); TFuture<void> future = promise.GetFuture() .Apply([&](const auto& theFuture) { return callback.FutureVoidFunc(theFuture); }); - + promise.SetValue(456); UNIT_ASSERT(!future.HasValue()); - + callback.Signal.SetValue(); UNIT_ASSERT(future.HasValue()); } - + Y_UNIT_TEST(ShouldIgnoreResultIfAsked) { TPromise<int> promise = NewPromise<int>(); - + TTestCallback callback(123); TFuture<int> future = promise.GetFuture().IgnoreResult().Return(42); - + promise.SetValue(456); UNIT_ASSERT_EQUAL(future.GetValue(), 42); } - + class TCustomException: public yexception { }; - + Y_UNIT_TEST(ShouldRethrowException) { TPromise<int> promise = NewPromise<int>(); try { @@ -238,7 +238,7 @@ namespace { UNIT_ASSERT_EXCEPTION(promise.GetValue(), TCustomException); UNIT_ASSERT_EXCEPTION(promise.TryRethrow(), TCustomException); } - + Y_UNIT_TEST(ShouldRethrowCallbackException) { TPromise<int> promise = NewPromise<int>(); TFuture<int> future = promise.GetFuture(); @@ -263,21 +263,21 @@ namespace { Y_UNIT_TEST(ShouldWaitExceptionOrAll) { TPromise<void> promise1 = NewPromise(); TPromise<void> promise2 = NewPromise(); - + TFuture<void> future = WaitExceptionOrAll(promise1, promise2); UNIT_ASSERT(!future.HasValue()); - + promise1.SetValue(); UNIT_ASSERT(!future.HasValue()); - + promise2.SetValue(); UNIT_ASSERT(future.HasValue()); } - + Y_UNIT_TEST(ShouldWaitExceptionOrAllVector) { TPromise<void> promise1 = NewPromise(); TPromise<void> promise2 = NewPromise(); - + TVector<TFuture<void>> promises; promises.push_back(promise1); promises.push_back(promise2); @@ -403,21 +403,21 @@ namespace { TFuture<void> future = WaitAny(promise1, promise2); UNIT_ASSERT(!future.HasValue()); - + promise1.SetValue(); UNIT_ASSERT(future.HasValue()); - + promise2.SetValue(); UNIT_ASSERT(future.HasValue()); } - + Y_UNIT_TEST(ShouldStoreTypesWithoutDefaultConstructor) { // compileability test struct TRec { explicit TRec(int) { } }; - + auto promise = NewPromise<TRec>(); promise.SetValue(TRec(1)); @@ -425,22 +425,22 @@ namespace { const auto& rec = future.GetValue(); Y_UNUSED(rec); } - + Y_UNIT_TEST(ShouldStoreMovableTypes) { // compileability test struct TRec : TMoveOnly { explicit TRec(int) { } }; - + auto promise = NewPromise<TRec>(); promise.SetValue(TRec(1)); - + auto future = MakeFuture(TRec(1)); const auto& rec = future.GetValue(); Y_UNUSED(rec); } - + Y_UNIT_TEST(ShouldMoveMovableTypes) { // compileability test struct TRec : TMoveOnly { diff --git a/library/cpp/threading/future/perf/main.cpp b/library/cpp/threading/future/perf/main.cpp index 71e9e293de..5a0690af47 100644 --- a/library/cpp/threading/future/perf/main.cpp +++ b/library/cpp/threading/future/perf/main.cpp @@ -1,50 +1,50 @@ #include <library/cpp/testing/benchmark/bench.h> #include <library/cpp/threading/future/future.h> - + #include <util/generic/string.h> -#include <util/generic/xrange.h> - -using namespace NThreading; - -template <typename T> +#include <util/generic/xrange.h> + +using namespace NThreading; + +template <typename T> void TestAllocPromise(const NBench::NCpu::TParams& iface) { for (const auto it : xrange(iface.Iterations())) { - Y_UNUSED(it); - Y_DO_NOT_OPTIMIZE_AWAY(NewPromise<T>()); - } -} - -template <typename T> + Y_UNUSED(it); + Y_DO_NOT_OPTIMIZE_AWAY(NewPromise<T>()); + } +} + +template <typename T> TPromise<T> SetPromise(T value) { - auto promise = NewPromise<T>(); - promise.SetValue(value); - return promise; -} - -template <typename T> + auto promise = NewPromise<T>(); + promise.SetValue(value); + return promise; +} + +template <typename T> void TestSetPromise(const NBench::NCpu::TParams& iface, T value) { for (const auto it : xrange(iface.Iterations())) { - Y_UNUSED(it); - Y_DO_NOT_OPTIMIZE_AWAY(SetPromise(value)); - } -} - + Y_UNUSED(it); + Y_DO_NOT_OPTIMIZE_AWAY(SetPromise(value)); + } +} + Y_CPU_BENCHMARK(AllocPromiseVoid, iface) { - TestAllocPromise<void>(iface); -} - + TestAllocPromise<void>(iface); +} + Y_CPU_BENCHMARK(AllocPromiseUI64, iface) { - TestAllocPromise<ui64>(iface); -} - + TestAllocPromise<ui64>(iface); +} + Y_CPU_BENCHMARK(AllocPromiseStroka, iface) { TestAllocPromise<TString>(iface); -} - +} + Y_CPU_BENCHMARK(SetPromiseUI64, iface) { - TestSetPromise<ui64>(iface, 1234567890ull); -} - + TestSetPromise<ui64>(iface, 1234567890ull); +} + Y_CPU_BENCHMARK(SetPromiseStroka, iface) { TestSetPromise<TString>(iface, "test test test"); -} +} diff --git a/library/cpp/threading/future/perf/ya.make b/library/cpp/threading/future/perf/ya.make index b56e66a838..943d585d4b 100644 --- a/library/cpp/threading/future/perf/ya.make +++ b/library/cpp/threading/future/perf/ya.make @@ -1,16 +1,16 @@ Y_BENCHMARK(library-threading-future-perf) - + OWNER( g:rtmr ishfb ) - -SRCS( - main.cpp -) - -PEERDIR( + +SRCS( + main.cpp +) + +PEERDIR( library/cpp/threading/future -) - -END() +) + +END() diff --git a/library/cpp/threading/future/ut/ya.make b/library/cpp/threading/future/ut/ya.make index c4d5a7e1d2..566b622370 100644 --- a/library/cpp/threading/future/ut/ya.make +++ b/library/cpp/threading/future/ut/ya.make @@ -6,7 +6,7 @@ OWNER( ) SRCS( - async_ut.cpp + async_ut.cpp future_ut.cpp legacy_future_ut.cpp ) diff --git a/library/cpp/threading/future/wait/wait-inl.h b/library/cpp/threading/future/wait/wait-inl.h index f778cf7fd5..2753d5446c 100644 --- a/library/cpp/threading/future/wait/wait-inl.h +++ b/library/cpp/threading/future/wait/wait-inl.h @@ -1,16 +1,16 @@ -#pragma once - -#if !defined(INCLUDE_FUTURE_INL_H) +#pragma once + +#if !defined(INCLUDE_FUTURE_INL_H) #error "you should never include wait-inl.h directly" #endif // INCLUDE_FUTURE_INL_H - + namespace NThreading { namespace NImpl { template <typename TContainer> TVector<TFuture<void>> ToVoidFutures(const TContainer& futures) { TVector<TFuture<void>> voidFutures; voidFutures.reserve(futures.size()); - + for (const auto& future: futures) { voidFutures.push_back(future.IgnoreResult()); } @@ -18,7 +18,7 @@ namespace NThreading { return voidFutures; } } - + template <typename TContainer> [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitAll(const TContainer& futures) { return WaitAll(NImpl::ToVoidFutures(futures)); @@ -27,10 +27,10 @@ namespace NThreading { template <typename TContainer> [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitExceptionOrAll(const TContainer& futures) { return WaitExceptionOrAll(NImpl::ToVoidFutures(futures)); - } + } template <typename TContainer> [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitAny(const TContainer& futures) { return WaitAny(NImpl::ToVoidFutures(futures)); - } -} + } +} diff --git a/library/cpp/threading/future/wait/wait.cpp b/library/cpp/threading/future/wait/wait.cpp index 5d040985f2..a173833a7f 100644 --- a/library/cpp/threading/future/wait/wait.cpp +++ b/library/cpp/threading/future/wait/wait.cpp @@ -1,5 +1,5 @@ #include "wait.h" - + #include "wait_group.h" #include "wait_policy.h" @@ -9,16 +9,16 @@ namespace NThreading { TFuture<void> WaitGeneric(const TFuture<void>& f1) { return f1; } - + template <class WaitPolicy> TFuture<void> WaitGeneric(const TFuture<void>& f1, const TFuture<void>& f2) { TWaitGroup<WaitPolicy> wg; - + wg.Add(f1).Add(f2); - + return std::move(wg).Finish(); } - + template <class WaitPolicy> TFuture<void> WaitGeneric(TArrayRef<const TFuture<void>> futures) { if (futures.empty()) { @@ -32,13 +32,13 @@ namespace NThreading { for (const auto& fut : futures) { wg.Add(fut); } - + return std::move(wg).Finish(); } } - + //////////////////////////////////////////////////////////////////////////////// - + TFuture<void> WaitAll(const TFuture<void>& f1) { return WaitGeneric<TWaitPolicy::TAll>(f1); } @@ -57,26 +57,26 @@ namespace NThreading { TFuture<void> WaitExceptionOrAll(const TFuture<void>& f1) { return WaitGeneric<TWaitPolicy::TExceptionOrAll>(f1); } - + TFuture<void> WaitExceptionOrAll(const TFuture<void>& f1, const TFuture<void>& f2) { return WaitGeneric<TWaitPolicy::TExceptionOrAll>(f1, f2); } - + TFuture<void> WaitExceptionOrAll(TArrayRef<const TFuture<void>> futures) { return WaitGeneric<TWaitPolicy::TExceptionOrAll>(futures); - } + } //////////////////////////////////////////////////////////////////////////////// - + TFuture<void> WaitAny(const TFuture<void>& f1) { return WaitGeneric<TWaitPolicy::TAny>(f1); } - + TFuture<void> WaitAny(const TFuture<void>& f1, const TFuture<void>& f2) { return WaitGeneric<TWaitPolicy::TAny>(f1, f2); } - + TFuture<void> WaitAny(TArrayRef<const TFuture<void>> futures) { return WaitGeneric<TWaitPolicy::TAny>(futures); - } -} + } +} diff --git a/library/cpp/threading/future/wait/wait.h b/library/cpp/threading/future/wait/wait.h index bfccede548..6ff7d57baa 100644 --- a/library/cpp/threading/future/wait/wait.h +++ b/library/cpp/threading/future/wait/wait.h @@ -1,10 +1,10 @@ -#pragma once - +#pragma once + #include "fwd.h" #include <library/cpp/threading/future/core/future.h> #include <library/cpp/threading/future/wait/wait_group.h> - + #include <util/generic/array_ref.h> namespace NThreading { @@ -27,7 +27,7 @@ namespace NThreading { [[nodiscard]] TFuture<void> WaitExceptionOrAll(TArrayRef<const TFuture<void>> futures); template <typename TContainer> [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitExceptionOrAll(const TContainer& futures); - + // waits for any future [[nodiscard]] TFuture<void> WaitAny(const TFuture<void>& f1); [[nodiscard]] TFuture<void> WaitAny(const TFuture<void>& f1, const TFuture<void>& f2); @@ -35,7 +35,7 @@ namespace NThreading { template <typename TContainer> [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitAny(const TContainer& futures); } - -#define INCLUDE_FUTURE_INL_H + +#define INCLUDE_FUTURE_INL_H #include "wait-inl.h" -#undef INCLUDE_FUTURE_INL_H +#undef INCLUDE_FUTURE_INL_H diff --git a/library/cpp/threading/future/ya.make b/library/cpp/threading/future/ya.make index 3a0db18662..6591031f46 100644 --- a/library/cpp/threading/future/ya.make +++ b/library/cpp/threading/future/ya.make @@ -4,7 +4,7 @@ OWNER( LIBRARY() -SRCS( +SRCS( async.cpp core/future.cpp core/fwd.cpp @@ -13,8 +13,8 @@ SRCS( wait/wait.cpp wait/wait_group.cpp wait/wait_policy.cpp -) - +) + END() RECURSE_FOR_TESTS( diff --git a/library/cpp/threading/skip_list/compare.h b/library/cpp/threading/skip_list/compare.h index c63003d67f..ac98b3e1ce 100644 --- a/library/cpp/threading/skip_list/compare.h +++ b/library/cpp/threading/skip_list/compare.h @@ -1,14 +1,14 @@ -#pragma once - -#include <util/generic/typetraits.h> -#include <util/str_stl.h> - -namespace NThreading { +#pragma once + +#include <util/generic/typetraits.h> +#include <util/str_stl.h> + +namespace NThreading { namespace NImpl { Y_HAS_MEMBER(compare); Y_HAS_MEMBER(Compare); - - template <typename T> + + template <typename T> inline int CompareImpl(const T& l, const T& r) { if (l < r) { return -1; @@ -17,8 +17,8 @@ namespace NThreading { } else { return 0; } - } - + } + template <bool val> struct TSmallCompareSelector { template <typename T> @@ -26,7 +26,7 @@ namespace NThreading { return CompareImpl(l, r); } }; - + template <> struct TSmallCompareSelector<true> { template <typename T> @@ -34,7 +34,7 @@ namespace NThreading { return l.compare(r); } }; - + template <bool val> struct TBigCompareSelector { template <typename T> @@ -51,15 +51,15 @@ namespace NThreading { } }; - template <typename T> + template <typename T> struct TCompareSelector: public TBigCompareSelector<THasCompare<T>::value> { }; } - + //////////////////////////////////////////////////////////////////////////////// // Generic compare function - template <typename T> + template <typename T> inline int Compare(const T& l, const T& r) { return NImpl::TCompareSelector<T>::Compare(l, r); } @@ -72,6 +72,6 @@ namespace NThreading { inline int operator()(const T& l, const T& r) const { return Compare(l, r); } - }; - -} + }; + +} diff --git a/library/cpp/threading/skip_list/perf/main.cpp b/library/cpp/threading/skip_list/perf/main.cpp index 4e8d5b4082..4ad52049e7 100644 --- a/library/cpp/threading/skip_list/perf/main.cpp +++ b/library/cpp/threading/skip_list/perf/main.cpp @@ -1,56 +1,56 @@ #include <library/cpp/threading/skip_list/skiplist.h> - + #include <library/cpp/getopt/small/last_getopt.h> #include <library/cpp/charset/ci_string.h> -#include <util/datetime/base.h> -#include <util/generic/map.h> -#include <util/generic/vector.h> +#include <util/datetime/base.h> +#include <util/generic/map.h> +#include <util/generic/vector.h> #include <functional> -#include <util/memory/pool.h> -#include <util/random/random.h> -#include <util/string/join.h> -#include <util/system/mutex.h> -#include <util/system/thread.h> - -namespace { +#include <util/memory/pool.h> +#include <util/random/random.h> +#include <util/string/join.h> +#include <util/system/mutex.h> +#include <util/system/thread.h> + +namespace { using namespace NThreading; - + //////////////////////////////////////////////////////////////////////////////// - + IOutputStream& LogInfo() { return Cerr << TInstant::Now() << " INFO: "; } - + IOutputStream& LogError() { return Cerr << TInstant::Now() << " ERROR: "; } - + //////////////////////////////////////////////////////////////////////////////// - + struct TListItem { TStringBuf Key; TStringBuf Value; - + TListItem(const TStringBuf& key, const TStringBuf& value) : Key(key) , Value(value) { } - + int Compare(const TListItem& other) const { return Key.compare(other.Key); } }; - + using TListType = TSkipList<TListItem>; - + //////////////////////////////////////////////////////////////////////////////// - + class TRandomData { private: TVector<char> Buffer; - + public: TRandomData() : Buffer(1024 * 1024) @@ -59,34 +59,34 @@ namespace { Buffer[i] = RandomNumber<char>(); } } - + TStringBuf GetString(size_t len) const { size_t start = RandomNumber(Buffer.size() - len); return TStringBuf(&Buffer[start], len); - } - + } + TStringBuf GetString(size_t min, size_t max) const { return GetString(min + RandomNumber(max - min)); } }; - + //////////////////////////////////////////////////////////////////////////////// - + class TWorkerThread: public ISimpleThread { private: std::function<void()> Func; TDuration Time; - + public: TWorkerThread(std::function<void()> func) : Func(func) { } - + TDuration GetTime() const { return Time; } - + private: void* ThreadProc() noexcept override { TInstant started = TInstant::Now(); @@ -95,33 +95,33 @@ namespace { return nullptr; } }; - + inline TAutoPtr<TWorkerThread> StartThread(std::function<void()> func) { TAutoPtr<TWorkerThread> thread = new TWorkerThread(func); thread->Start(); return thread; - } - + } + //////////////////////////////////////////////////////////////////////////////// - + typedef std::function<void()> TTestFunc; - + struct TTest { TString Name; TTestFunc Func; - + TTest() { } - + TTest(const TString& name, const TTestFunc& func) : Name(name) , Func(func) { } }; - + //////////////////////////////////////////////////////////////////////////////// - + class TTestSuite { private: size_t Iterations = 1000000; @@ -130,72 +130,72 @@ namespace { size_t NumReaders = 4; size_t NumWriters = 1; size_t BatchSize = 20; - + TMemoryPool MemoryPool; TListType List; TMutex Mutex; TRandomData Random; - + TMap<TCiString, TTest> AllTests; TVector<TTest> Tests; - + public: TTestSuite() : MemoryPool(64 * 1024) , List(MemoryPool) { } - + bool Init(int argc, const char* argv[]) { TVector<TString> tests; try { NLastGetopt::TOpts opts; opts.AddHelpOption(); - + #define OPTION(opt, x) \ opts.AddLongOption(opt, #x) \ .Optional() \ .DefaultValue(ToString(x)) \ .StoreResult(&x) // end of OPTION - + OPTION('i', Iterations); OPTION('k', KeyLen); OPTION('v', ValueLen); OPTION('r', NumReaders); OPTION('w', NumWriters); OPTION('b', BatchSize); - -#undef OPTION - + +#undef OPTION + NLastGetopt::TOptsParseResultException optsRes(&opts, argc, argv); for (const auto& opt : opts.Opts_) { const NLastGetopt::TOptParseResult* r = optsRes.FindOptParseResult(opt.Get(), true); if (r) { LogInfo() << "[-" << opt->GetChar() << "] " << opt->GetName() << ": " << r->Back() << Endl; } - } + } tests = optsRes.GetFreeArgs(); } catch (...) { LogError() << CurrentExceptionMessage() << Endl; return false; - } - -#define TEST(type) \ + } + +#define TEST(type) \ AddTest(#type, std::bind(&TTestSuite::Y_CAT(TEST_, type), this)) // end of TEST - + TEST(Clear); TEST(InsertRandom); TEST(InsertSequential); TEST(InsertSequentialSimple); TEST(LookupRandom); TEST(Concurrent); - -#undef TEST - + +#undef TEST + if (tests.empty()) { LogError() << "no tests specified, choose from: " << PrintTests() << Endl; - return false; - } + return false; + } for (size_t i = 0; i < tests.size(); ++i) { if (!AllTests.contains(tests[i])) { @@ -206,13 +206,13 @@ namespace { } return true; - } - + } + void Run() { -#if !defined(NDEBUG) +#if !defined(NDEBUG) LogInfo() << "*** DEBUG build! ***" << Endl; -#endif - +#endif + for (const TTest& test : Tests) { LogInfo() << "Starting test " << test.Name << Endl; @@ -224,7 +224,7 @@ namespace { << " failed: " << CurrentExceptionMessage() << Endl; } - + LogInfo() << "List size = " << List.GetSize() << Endl; TDuration duration = TInstant::Now() - started; @@ -234,31 +234,31 @@ namespace { << Endl; LogInfo() << "Finished test " << test.Name << Endl; } - } - + } + private: void AddTest(const char* name, TTestFunc func) { AllTests[name] = TTest(name, func); } - + TString PrintTests() const { TVector<TString> names; for (const auto& it : AllTests) { names.push_back(it.first); } return JoinSeq(", ", names); - } - + } + void TEST_Clear() { List.Clear(); } - + void TEST_InsertRandom() { for (size_t i = 0; i < Iterations; ++i) { List.Insert(TListItem(Random.GetString(KeyLen), Random.GetString(ValueLen))); } - } - + } + void TEST_InsertSequential() { TString key; for (size_t i = 0; i < Iterations;) { @@ -269,9 +269,9 @@ namespace { key.append((char)j); List.Insert(TListItem(key, Random.GetString(ValueLen))); } - } - } - + } + } + void TEST_InsertSequentialSimple() { for (size_t i = 0; i < Iterations; ++i) { List.Insert(TListItem(Random.GetString(KeyLen), Random.GetString(ValueLen))); @@ -282,11 +282,11 @@ namespace { for (size_t i = 0; i < Iterations; ++i) { List.SeekTo(TListItem(Random.GetString(KeyLen), TStringBuf())); } - } - + } + void TEST_Concurrent() { LogInfo() << "starting producers..." << Endl; - + TVector<TAutoPtr<TWorkerThread>> producers(NumWriters); for (size_t i1 = 0; i1 < producers.size(); ++i1) { producers[i1] = StartThread([&] { @@ -304,9 +304,9 @@ namespace { << Endl; }); } - + LogInfo() << "starting consumers..." << Endl; - + TVector<TAutoPtr<TWorkerThread>> consumers(NumReaders); for (size_t i1 = 0; i1 < consumers.size(); ++i1) { consumers[i1] = StartThread([&] { @@ -321,42 +321,42 @@ namespace { << Endl; }); } - + LogInfo() << "wait for producers..." << Endl; - + TDuration producerTime; for (size_t i = 0; i < producers.size(); ++i) { producers[i]->Join(); producerTime += producers[i]->GetTime(); } - + LogInfo() << "wait for consumers..." << Endl; - + TDuration consumerTime; for (size_t i = 0; i < consumers.size(); ++i) { consumers[i]->Join(); consumerTime += consumers[i]->GetTime(); } - + LogInfo() << "average producer time: " << producerTime.SecondsFloat() / producers.size() << " seconds" << Endl; - + LogInfo() << "average consumer time: " << consumerTime.SecondsFloat() / consumers.size() << " seconds" << Endl; } }; - + } - -//////////////////////////////////////////////////////////////////////////////// - + +//////////////////////////////////////////////////////////////////////////////// + int main(int argc, const char* argv[]) { - TTestSuite suite; - if (!suite.Init(argc, argv)) { - return -1; - } - suite.Run(); - return 0; -} + TTestSuite suite; + if (!suite.Init(argc, argv)) { + return -1; + } + suite.Run(); + return 0; +} diff --git a/library/cpp/threading/skip_list/perf/ya.make b/library/cpp/threading/skip_list/perf/ya.make index d64a58a60e..01bfafa404 100644 --- a/library/cpp/threading/skip_list/perf/ya.make +++ b/library/cpp/threading/skip_list/perf/ya.make @@ -1,15 +1,15 @@ -PROGRAM(skiplist-perf) - +PROGRAM(skiplist-perf) + OWNER(g:rtmr) - -PEERDIR( + +PEERDIR( library/cpp/charset library/cpp/getopt/small library/cpp/threading/skip_list -) - -SRCS( - main.cpp -) - -END() +) + +SRCS( + main.cpp +) + +END() diff --git a/library/cpp/threading/skip_list/skiplist.cpp b/library/cpp/threading/skip_list/skiplist.cpp index 386b9546d4..c6e98816fb 100644 --- a/library/cpp/threading/skip_list/skiplist.cpp +++ b/library/cpp/threading/skip_list/skiplist.cpp @@ -1 +1 @@ -#include "skiplist.h" +#include "skiplist.h" diff --git a/library/cpp/threading/skip_list/skiplist.h b/library/cpp/threading/skip_list/skiplist.h index 054a1b10b9..914a7c6ee7 100644 --- a/library/cpp/threading/skip_list/skiplist.h +++ b/library/cpp/threading/skip_list/skiplist.h @@ -1,69 +1,69 @@ -#pragma once - -#include "compare.h" - -#include <util/generic/algorithm.h> -#include <util/generic/noncopyable.h> -#include <util/generic/typetraits.h> -#include <util/memory/pool.h> -#include <util/random/random.h> -#include <util/system/atomic.h> - -namespace NThreading { +#pragma once + +#include "compare.h" + +#include <util/generic/algorithm.h> +#include <util/generic/noncopyable.h> +#include <util/generic/typetraits.h> +#include <util/memory/pool.h> +#include <util/random/random.h> +#include <util/system/atomic.h> + +namespace NThreading { //////////////////////////////////////////////////////////////////////////////// - + class TNopCounter { protected: template <typename T> void OnInsert(const T&) { } - + template <typename T> void OnUpdate(const T&) { } - + void Reset() { } }; - + //////////////////////////////////////////////////////////////////////////////// - + class TSizeCounter { - private: + private: size_t Size; - - public: + + public: TSizeCounter() : Size(0) - { - } - + { + } + size_t GetSize() const { return Size; - } - + } + protected: template <typename T> void OnInsert(const T&) { ++Size; - } - + } + template <typename T> void OnUpdate(const T&) { - } - + } + void Reset() { Size = 0; - } - }; - + } + }; + //////////////////////////////////////////////////////////////////////////////// // Append-only concurrent skip-list // // Readers do not require any synchronization. // Writers should be externally synchronized. // Nodes will be allocated using TMemoryPool instance. - + template < typename T, typename TComparer = TCompare<T>, @@ -104,41 +104,41 @@ namespace NThreading { } }; - public: + public: class TIterator { private: const TSkipList* List; const TNode* Node; - + public: TIterator() : List(nullptr) , Node(nullptr) { } - + TIterator(const TSkipList* list, const TNode* node) : List(list) , Node(node) { } - + TIterator(const TIterator& other) : List(other.List) , Node(other.Node) { } - + TIterator& operator=(const TIterator& other) { List = other.List; Node = other.Node; return *this; } - + void Next() { Node = Node ? Node->GetNext(0) : nullptr; - } - + } + // much less efficient than Next as our list is single-linked void Prev() { if (Node) { @@ -146,34 +146,34 @@ namespace NThreading { Node = (node != List->Head ? node : nullptr); } } - + void Reset() { Node = nullptr; } - + bool IsValid() const { return Node != nullptr; } - + const T& GetValue() const { Y_ASSERT(IsValid()); return Node->GetValue(); } }; - + private: TAllocator& Allocator; TComparer Comparer; - + TNode* Head; TAtomic Height; TCounter Counter; - + TNode* Prev[MaxHeight]; - + template <typename TValue> using TComparerReturnType = std::invoke_result_t<TComparer, const T&, const TValue&>; - + public: TSkipList(TAllocator& allocator, const TComparer& comparer = TComparer()) : Allocator(allocator) @@ -181,28 +181,28 @@ namespace NThreading { { Init(); } - + ~TSkipList() { CallDtors(); } - + void Clear() { CallDtors(); Allocator.ClearKeepFirstChunk(); Init(); - } - + } + bool Insert(T value) { TNode* node = PrepareInsert(value); if (Y_UNLIKELY(node && Compare(node, value) == 0)) { // we do not allow duplicates return false; - } + } node = DoInsert(std::move(value)); TCounter::OnInsert(node->GetValue()); return true; - } - + } + template <typename TInsertAction, typename TUpdateAction> bool Insert(const T& value, TInsertAction insert, TUpdateAction update) { TNode* node = PrepareInsert(value); @@ -218,27 +218,27 @@ namespace NThreading { TCounter::OnInsert(node->GetValue()); return true; } - + template <typename TValue> bool Contains(const TValue& value) const { TNode* node = FindGreaterThanOrEqual(value); return node && Compare(node, value) == 0; } - + TIterator SeekToFirst() const { return TIterator(this, FindFirst()); } - + TIterator SeekToLast() const { TNode* last = FindLast(); return TIterator(this, last != Head ? last : nullptr); } - + template <typename TValue> TIterator SeekTo(const TValue& value) const { return TIterator(this, FindGreaterThanOrEqual(value)); - } - + } + private: static int RandomHeight() { int height = 1; @@ -247,7 +247,7 @@ namespace NThreading { } return height; } - + void Init() { Head = AllocateRootNode(); Height = 1; @@ -256,8 +256,8 @@ namespace NThreading { for (int i = 0; i < MaxHeight; ++i) { Prev[i] = Head; } - } - + } + void CallDtors() { if (!TTypeTraits<T>::IsPod) { // we should explicitly call destructors for our nodes @@ -267,56 +267,56 @@ namespace NThreading { node->~TNode(); node = next; } - } - } - + } + } + TNode* AllocateRootNode() { size_t size = sizeof(TNode) + sizeof(TNode*) * MaxHeight; void* buffer = Allocator.Allocate(size); memset(buffer, 0, size); return static_cast<TNode*>(buffer); } - + TNode* AllocateNode(T&& value, int height) { size_t size = sizeof(TNode) + sizeof(TNode*) * height; void* buffer = Allocator.Allocate(size); memset(buffer, 0, size); return new (buffer) TNode(std::move(value)); } - + TNode* FindFirst() const { return Head->GetNext(0); } - + TNode* FindLast() const { TNode* node = Head; int height = AtomicGet(Height) - 1; - + while (true) { TNode* next = node->GetNext(height); if (next) { node = next; continue; } - + if (height) { --height; } else { return node; } - } - } - + } + } + template <typename TValue> TComparerReturnType<TValue> Compare(const TNode* node, const TValue& value) const { return Comparer(node->GetValue(), value); } - + template <typename TValue> TNode* FindLessThan(const TValue& value, TNode** links) const { TNode* node = Head; int height = AtomicGet(Height) - 1; - + TNode* prev = nullptr; while (true) { TNode* next = node->GetNext(height); @@ -326,27 +326,27 @@ namespace NThreading { node = next; continue; } - } - + } + if (links) { // collect links from upper levels links[height] = node; } - + if (height) { prev = next; --height; } else { return node; } - } - } - + } + } + template <typename TValue> TNode* FindGreaterThanOrEqual(const TValue& value) const { TNode* node = Head; int height = AtomicGet(Height) - 1; - + TNode* prev = nullptr; while (true) { TNode* next = node->GetNext(height); @@ -359,29 +359,29 @@ namespace NThreading { if (cmp == 0) { return next; } - } + } if (height) { prev = next; --height; } else { - return next; - } - } + return next; + } + } } - + TNode* PrepareInsert(const T& value) { TNode* prev = Prev[0]; TNode* next = prev->GetNext(0); if ((prev == Head || Compare(prev, value) < 0) && (next == nullptr || Compare(next, value) >= 0)) { // avoid seek in case of sequential insert - } else { + } else { prev = FindLessThan(value, Prev); next = prev->GetNext(0); - } + } return next; - } - + } + TNode* DoInsert(T&& value) { // choose level to place new node int currentHeight = AtomicGet(Height); @@ -392,17 +392,17 @@ namespace NThreading { Prev[i] = Head; } AtomicSet(Height, height); - } - + } + TNode* node = AllocateNode(std::move(value), height); node->Link(height, Prev); - + // keep last inserted node to optimize sequential inserts for (int i = 0; i < height; i++) { Prev[i] = node; } return node; - } + } }; - + } diff --git a/library/cpp/threading/skip_list/skiplist_ut.cpp b/library/cpp/threading/skip_list/skiplist_ut.cpp index e7d0b62873..52fcffda66 100644 --- a/library/cpp/threading/skip_list/skiplist_ut.cpp +++ b/library/cpp/threading/skip_list/skiplist_ut.cpp @@ -1,91 +1,91 @@ -#include "skiplist.h" - +#include "skiplist.h" + #include <library/cpp/testing/unittest/registar.h> - -namespace NThreading { + +namespace NThreading { namespace { struct TTestObject { static size_t Count; int Tag; - + TTestObject(int tag) : Tag(tag) { ++Count; } - + TTestObject(const TTestObject& other) : Tag(other.Tag) { ++Count; } - + ~TTestObject() { --Count; } - + bool operator<(const TTestObject& other) const { return Tag < other.Tag; } }; - + size_t TTestObject::Count = 0; - - } - + + } + //////////////////////////////////////////////////////////////////////////////// - + Y_UNIT_TEST_SUITE(TSkipListTest) { Y_UNIT_TEST(ShouldBeEmptyAfterCreation) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + UNIT_ASSERT_EQUAL(list.GetSize(), 0); } - + Y_UNIT_TEST(ShouldAllowInsertion) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + UNIT_ASSERT(list.Insert(12345678)); UNIT_ASSERT_EQUAL(list.GetSize(), 1); } - + Y_UNIT_TEST(ShouldNotAllowDuplicates) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + UNIT_ASSERT(list.Insert(12345678)); UNIT_ASSERT_EQUAL(list.GetSize(), 1); - + UNIT_ASSERT(!list.Insert(12345678)); UNIT_ASSERT_EQUAL(list.GetSize(), 1); } - + Y_UNIT_TEST(ShouldContainInsertedItem) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + UNIT_ASSERT(list.Insert(12345678)); UNIT_ASSERT(list.Contains(12345678)); } - + Y_UNIT_TEST(ShouldNotContainNotInsertedItem) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + UNIT_ASSERT(list.Insert(12345678)); UNIT_ASSERT(!list.Contains(87654321)); } - + Y_UNIT_TEST(ShouldIterateAllItems) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + for (int i = 8; i > 0; --i) { UNIT_ASSERT(list.Insert(i)); } - + TSkipList<int>::TIterator it = list.SeekToFirst(); for (int i = 1; i <= 8; ++i) { UNIT_ASSERT(it.IsValid()); @@ -94,15 +94,15 @@ namespace NThreading { } UNIT_ASSERT(!it.IsValid()); } - + Y_UNIT_TEST(ShouldIterateAllItemsInReverseDirection) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + for (int i = 8; i > 0; --i) { UNIT_ASSERT(list.Insert(i)); } - + TSkipList<int>::TIterator it = list.SeekToLast(); for (int i = 8; i > 0; --i) { UNIT_ASSERT(it.IsValid()); @@ -111,75 +111,75 @@ namespace NThreading { } UNIT_ASSERT(!it.IsValid()); } - + Y_UNIT_TEST(ShouldSeekToFirstItem) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + for (int i = 1; i < 10; ++i) { UNIT_ASSERT(list.Insert(i)); } - + TSkipList<int>::TIterator it = list.SeekToFirst(); UNIT_ASSERT(it.IsValid()); UNIT_ASSERT_EQUAL(it.GetValue(), 1); } - + Y_UNIT_TEST(ShouldSeekToLastItem) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + for (int i = 1; i < 10; ++i) { UNIT_ASSERT(list.Insert(i)); } - + TSkipList<int>::TIterator it = list.SeekToLast(); UNIT_ASSERT(it.IsValid()); UNIT_ASSERT_EQUAL(it.GetValue(), 9); } - + Y_UNIT_TEST(ShouldSeekToExistingItem) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + UNIT_ASSERT(list.Insert(12345678)); - + TSkipList<int>::TIterator it = list.SeekTo(12345678); UNIT_ASSERT(it.IsValid()); } - + Y_UNIT_TEST(ShouldSeekAfterMissedItem) { TMemoryPool pool(1024); TSkipList<int> list(pool); - + UNIT_ASSERT(list.Insert(100)); UNIT_ASSERT(list.Insert(300)); - + TSkipList<int>::TIterator it = list.SeekTo(200); UNIT_ASSERT(it.IsValid()); UNIT_ASSERT_EQUAL(it.GetValue(), 300); - + it.Prev(); UNIT_ASSERT(it.IsValid()); UNIT_ASSERT_EQUAL(it.GetValue(), 100); } - + Y_UNIT_TEST(ShouldCallDtorsOfNonPodTypes) { UNIT_ASSERT(!TTypeTraits<TTestObject>::IsPod); UNIT_ASSERT_EQUAL(TTestObject::Count, 0); - + { TMemoryPool pool(1024); TSkipList<TTestObject> list(pool); - + UNIT_ASSERT(list.Insert(TTestObject(1))); UNIT_ASSERT(list.Insert(TTestObject(2))); - + UNIT_ASSERT_EQUAL(TTestObject::Count, 2); } UNIT_ASSERT_EQUAL(TTestObject::Count, 0); } - } - + } + } diff --git a/library/cpp/threading/skip_list/ut/ya.make b/library/cpp/threading/skip_list/ut/ya.make index ae07423e71..704a31e9a2 100644 --- a/library/cpp/threading/skip_list/ut/ya.make +++ b/library/cpp/threading/skip_list/ut/ya.make @@ -1,9 +1,9 @@ UNITTEST_FOR(library/cpp/threading/skip_list) - + OWNER(g:rtmr) - -SRCS( - skiplist_ut.cpp -) - -END() + +SRCS( + skiplist_ut.cpp +) + +END() diff --git a/library/cpp/threading/skip_list/ya.make b/library/cpp/threading/skip_list/ya.make index 923fcb3566..d338aeae2b 100644 --- a/library/cpp/threading/skip_list/ya.make +++ b/library/cpp/threading/skip_list/ya.make @@ -1,9 +1,9 @@ -LIBRARY() - +LIBRARY() + OWNER(g:rtmr) - -SRCS( - skiplist.cpp -) - -END() + +SRCS( + skiplist.cpp +) + +END() diff --git a/library/cpp/ytalloc/api/fallback.cpp b/library/cpp/ytalloc/api/fallback.cpp index 7b4e607cb7..5880ede439 100644 --- a/library/cpp/ytalloc/api/fallback.cpp +++ b/library/cpp/ytalloc/api/fallback.cpp @@ -19,13 +19,13 @@ Y_WEAK void* Allocate(size_t size) Y_WEAK void* AllocatePageAligned(size_t size) { -#if defined(_win_) - return ::_aligned_malloc(size, PageSize); +#if defined(_win_) + return ::_aligned_malloc(size, PageSize); #elif defined(_darwin_) || !defined(_musl_) return ::valloc(size); -#else +#else return ::memalign(PageSize, size); -#endif +#endif } Y_WEAK void* AllocateSmall(size_t rank) diff --git a/library/cpp/ytalloc/api/ytalloc.h b/library/cpp/ytalloc/api/ytalloc.h index 81684e724e..d942dde638 100644 --- a/library/cpp/ytalloc/api/ytalloc.h +++ b/library/cpp/ytalloc/api/ytalloc.h @@ -15,9 +15,9 @@ namespace NYT::NYTAlloc { //////////////////////////////////////////////////////////////////////////////// // Macros -#if defined(_linux_) && \ - !defined(_asan_enabled_) && \ - !defined(_msan_enabled_) && \ +#if defined(_linux_) && \ + !defined(_asan_enabled_) && \ + !defined(_msan_enabled_) && \ !defined(_tsan_enabled_) #define YT_ALLOC_ENABLED #endif diff --git a/util/datetime/base.h b/util/datetime/base.h index a08766a46d..5e902b8f63 100644 --- a/util/datetime/base.h +++ b/util/datetime/base.h @@ -307,7 +307,7 @@ public: return Hours(d * 24); } - /// parses strings like 10s, 15ms, 15.05s, 20us, or just 25 (s). See parser_ut.cpp for details + /// parses strings like 10s, 15ms, 15.05s, 20us, or just 25 (s). See parser_ut.cpp for details static TDuration Parse(const TStringBuf input); static bool TryParse(const TStringBuf input, TDuration& result); diff --git a/util/generic/deque.h b/util/generic/deque.h index b96f0ea2ba..2dabaf3177 100644 --- a/util/generic/deque.h +++ b/util/generic/deque.h @@ -12,7 +12,7 @@ template <class T, class A> class TDeque: public std::deque<T, TReboundAllocator<A, T>> { using TBase = std::deque<T, TReboundAllocator<A, T>>; -public: +public: using TBase::TBase; inline yssize_t ysize() const noexcept { diff --git a/util/generic/flags.h b/util/generic/flags.h index b47f7d02c0..a1f5921d42 100644 --- a/util/generic/flags.h +++ b/util/generic/flags.h @@ -234,11 +234,11 @@ struct THash<TFlags<Enum>> { * @param FLAGS Flags type to declare operator for. */ #define Y_DECLARE_OPERATORS_FOR_FLAGS(FLAGS) \ - Y_DECLARE_UNUSED \ + Y_DECLARE_UNUSED \ constexpr inline FLAGS operator|(FLAGS::TEnum l, FLAGS::TEnum r) { \ return FLAGS(l) | r; \ } \ - Y_DECLARE_UNUSED \ + Y_DECLARE_UNUSED \ constexpr inline FLAGS operator~(FLAGS::TEnum value) { \ return ~FLAGS(value); \ } diff --git a/util/generic/flags_ut.cpp b/util/generic/flags_ut.cpp index 23ab5a99f8..5377c6a058 100644 --- a/util/generic/flags_ut.cpp +++ b/util/generic/flags_ut.cpp @@ -22,15 +22,15 @@ enum class ETestFlag2 { Y_DECLARE_FLAGS(ETest2, ETestFlag2) Y_DECLARE_OPERATORS_FOR_FLAGS(ETest2) -namespace { - // won't compile without Y_DECLARE_UNUSED +namespace { + // won't compile without Y_DECLARE_UNUSED enum class ETestFlag3 { One = 1, Two = 2, Three = 3 }; - Y_DECLARE_FLAGS(ETestFlags3, ETestFlag3) - Y_DECLARE_OPERATORS_FOR_FLAGS(ETestFlags3) -} - + Y_DECLARE_FLAGS(ETestFlags3, ETestFlag3) + Y_DECLARE_OPERATORS_FOR_FLAGS(ETestFlags3) +} + Y_UNIT_TEST_SUITE(TFlagsTest) { template <class Enum> void TestEnum() { diff --git a/util/generic/hash.h b/util/generic/hash.h index 0fea17b3a5..e46db21fa9 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1561,39 +1561,39 @@ public: } public: - template <class InputIterator> - void insert(InputIterator f, InputIterator l) { - rep.insert_unique(f, l); - } - + template <class InputIterator> + void insert(InputIterator f, InputIterator l) { + rep.insert_unique(f, l); + } + std::pair<iterator, bool> insert(const value_type& obj) { return rep.insert_unique(obj); } - + template <typename... Args> std::pair<iterator, bool> emplace(Args&&... args) { return rep.emplace_unique(std::forward<Args>(args)...); } - - std::pair<iterator, bool> insert_noresize(const value_type& obj) { - return rep.insert_unique_noresize(obj); - } - + + std::pair<iterator, bool> insert_noresize(const value_type& obj) { + return rep.insert_unique_noresize(obj); + } + template <typename... Args> std::pair<iterator, bool> emplace_noresize(Args&&... args) { return rep.emplace_unique_noresize(std::forward<Args>(args)...); } - + template <class TheObj> iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { return rep.insert_direct(obj, ins); } - template <typename... Args> - iterator emplace_direct(const insert_ctx& ins, Args&&... args) { - return rep.emplace_direct(ins, std::forward<Args>(args)...); - } - + template <typename... Args> + iterator emplace_direct(const insert_ctx& ins, Args&&... args) { + return rep.emplace_direct(ins, std::forward<Args>(args)...); + } + template <typename TKey, typename... Args> std::pair<iterator, bool> try_emplace(TKey&& key, Args&&... args) { insert_ctx ctx = nullptr; @@ -1776,7 +1776,7 @@ public: using iterator = typename ht::iterator; using const_iterator = typename ht::const_iterator; - using insert_ctx = typename ht::insert_ctx; + using insert_ctx = typename ht::insert_ctx; hasher hash_function() const { return rep.hash_function(); @@ -1886,55 +1886,55 @@ public: } public: - template <class InputIterator> - void insert(InputIterator f, InputIterator l) { - rep.insert_equal(f, l); - } - + template <class InputIterator> + void insert(InputIterator f, InputIterator l) { + rep.insert_equal(f, l); + } + iterator insert(const value_type& obj) { return rep.insert_equal(obj); } - - template <typename... Args> + + template <typename... Args> iterator emplace(Args&&... args) { return rep.emplace_equal(std::forward<Args>(args)...); } - + iterator insert_noresize(const value_type& obj) { return rep.emplace_equal_noresize(obj); } - template <typename... Args> - iterator emplace_noresize(Args&&... args) { - return rep.emplace_equal_noresize(std::forward<Args>(args)...); - } - - template <class TheObj> - iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { - return rep.insert_direct(obj, ins); - } - - template <typename... Args> - iterator emplace_direct(const insert_ctx& ins, Args&&... args) { - return rep.emplace_direct(ins, std::forward<Args>(args)...); - } - + template <typename... Args> + iterator emplace_noresize(Args&&... args) { + return rep.emplace_equal_noresize(std::forward<Args>(args)...); + } + + template <class TheObj> + iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { + return rep.insert_direct(obj, ins); + } + + template <typename... Args> + iterator emplace_direct(const insert_ctx& ins, Args&&... args) { + return rep.emplace_direct(ins, std::forward<Args>(args)...); + } + template <class TKey> - const_iterator find(const TKey& key) const { + const_iterator find(const TKey& key) const { return rep.find(key); } template <class TKey> - iterator find(const TKey& key) { + iterator find(const TKey& key) { return rep.find(key); } template <class TheKey> - iterator find(const TheKey& key, insert_ctx& ins) { - return rep.find_i(key, ins); - } - - template <class TheKey> + iterator find(const TheKey& key, insert_ctx& ins) { + return rep.find_i(key, ins); + } + + template <class TheKey> bool contains(const TheKey& key) const { return rep.find(key) != rep.end(); } diff --git a/util/generic/hash_set.h b/util/generic/hash_set.h index ac1ff92bbb..e8088cf23b 100644 --- a/util/generic/hash_set.h +++ b/util/generic/hash_set.h @@ -147,15 +147,15 @@ public: } public: - void insert(std::initializer_list<value_type> ilist) { - insert(ilist.begin(), ilist.end()); - } - - template <class InputIterator> - void insert(InputIterator f, InputIterator l) { - rep.insert_unique(f, l); - } - + void insert(std::initializer_list<value_type> ilist) { + insert(ilist.begin(), ilist.end()); + } + + template <class InputIterator> + void insert(InputIterator f, InputIterator l) { + rep.insert_unique(f, l); + } + std::pair<iterator, bool> insert(const value_type& obj) { std::pair<mutable_iterator, bool> p = rep.insert_unique(obj); return std::pair<iterator, bool>(p.first, p.second); @@ -165,8 +165,8 @@ public: std::pair<mutable_iterator, bool> p = rep.emplace_unique(std::forward<Args>(args)...); return std::pair<iterator, bool>(p.first, p.second); } - - iterator insert(const_iterator, const value_type& obj) { // insert_hint + + iterator insert(const_iterator, const value_type& obj) { // insert_hint std::pair<mutable_iterator, bool> p = rep.insert_unique(obj); return p.first; } @@ -180,25 +180,25 @@ public: std::pair<mutable_iterator, bool> p = rep.emplace_unique_noresize(std::forward<Args>(args)...); return std::pair<iterator, bool>(p.first, p.second); } - + template <class TheObj> iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { return rep.insert_direct(obj, ins); } - template <typename... Args> - iterator emplace_direct(const insert_ctx& ins, Args&&... args) { - return rep.emplace_direct(ins, std::forward<Args>(args)...); - } + template <typename... Args> + iterator emplace_direct(const insert_ctx& ins, Args&&... args) { + return rep.emplace_direct(ins, std::forward<Args>(args)...); + } template <class TheKey> - const_iterator find(const TheKey& key) const { + const_iterator find(const TheKey& key) const { return rep.find(key); } template <class TheKey> iterator find(const TheKey& key, insert_ctx& ins) { return rep.find_i(key, ins); } - + template <class TheKey> bool contains(const TheKey& key) const { return rep.find(key) != rep.end(); diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 53396409f3..0551d58770 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -38,16 +38,16 @@ class THashTest: public TTestBase { UNIT_TEST(TestAllocation); UNIT_TEST(TestInsertCopy); UNIT_TEST(TestEmplace); - UNIT_TEST(TestEmplaceNoresize); - UNIT_TEST(TestEmplaceDirect); + UNIT_TEST(TestEmplaceNoresize); + UNIT_TEST(TestEmplaceDirect); UNIT_TEST(TestTryEmplace); UNIT_TEST(TestTryEmplaceCopyKey); - UNIT_TEST(TestHMMapEmplace); - UNIT_TEST(TestHMMapEmplaceNoresize); - UNIT_TEST(TestHMMapEmplaceDirect); + UNIT_TEST(TestHMMapEmplace); + UNIT_TEST(TestHMMapEmplaceNoresize); + UNIT_TEST(TestHMMapEmplaceDirect); UNIT_TEST(TestHSetEmplace); - UNIT_TEST(TestHSetEmplaceNoresize); - UNIT_TEST(TestHSetEmplaceDirect); + UNIT_TEST(TestHSetEmplaceNoresize); + UNIT_TEST(TestHSetEmplaceDirect); UNIT_TEST(TestNonCopyable); UNIT_TEST(TestValueInitialization); UNIT_TEST(TestAssignmentClear); @@ -89,16 +89,16 @@ protected: void TestAllocation(); void TestInsertCopy(); void TestEmplace(); - void TestEmplaceNoresize(); - void TestEmplaceDirect(); + void TestEmplaceNoresize(); + void TestEmplaceDirect(); void TestTryEmplace(); void TestTryEmplaceCopyKey(); void TestHSetEmplace(); - void TestHSetEmplaceNoresize(); - void TestHSetEmplaceDirect(); - void TestHMMapEmplace(); - void TestHMMapEmplaceNoresize(); - void TestHMMapEmplaceDirect(); + void TestHSetEmplaceNoresize(); + void TestHSetEmplaceDirect(); + void TestHMMapEmplace(); + void TestHMMapEmplaceNoresize(); + void TestHMMapEmplaceDirect(); void TestNonCopyable(); void TestValueInitialization(); void TestAssignmentClear(); @@ -632,65 +632,65 @@ void THashTest::TestInsertErase() { UNIT_ASSERT(values.erase("foo") == 1); } } - -namespace { + +namespace { struct TItem: public TSimpleRefCount<TItem> { const TString Key; const TString Value; - + TItem(const TString& key, const TString& value) - : Key(key) - , Value(value) + : Key(key) + , Value(value) { } - }; - + }; + using TItemPtr = TIntrusivePtr<TItem>; - - struct TSelectKey { + + struct TSelectKey { const TString& operator()(const TItemPtr& item) const { - return item->Key; - } - }; - + return item->Key; + } + }; + using TItemMapBase = THashTable< - TItemPtr, + TItemPtr, TString, THash<TString>, - TSelectKey, + TSelectKey, TEqualTo<TString>, std::allocator<TItemPtr>>; - - struct TItemMap: public TItemMapBase { - TItemMap() + + struct TItemMap: public TItemMapBase { + TItemMap() : TItemMapBase(1, THash<TString>(), TEqualTo<TString>()) { } - + TItem& Add(const TString& key, const TString& value) { - insert_ctx ins; - iterator it = find_i(key, ins); - if (it == end()) { - it = insert_direct(new TItem(key, value), ins); - } - return **it; - } - }; + insert_ctx ins; + iterator it = find_i(key, ins); + if (it == end()) { + it = insert_direct(new TItem(key, value), ins); + } + return **it; + } + }; +} + +void THashTest::TestResizeOnInsertSmartPtrBug() { + TItemMap map; + map.Add("key1", "value1"); + map.Add("key2", "value2"); + map.Add("key3", "value3"); + map.Add("key4", "value4"); + map.Add("key5", "value5"); + map.Add("key6", "value6"); + map.Add("key7", "value7"); + TItem& item = map.Add("key8", "value8"); + UNIT_ASSERT_EQUAL(item.Key, "key8"); + UNIT_ASSERT_EQUAL(item.Value, "value8"); } - -void THashTest::TestResizeOnInsertSmartPtrBug() { - TItemMap map; - map.Add("key1", "value1"); - map.Add("key2", "value2"); - map.Add("key3", "value3"); - map.Add("key4", "value4"); - map.Add("key5", "value5"); - map.Add("key6", "value6"); - map.Add("key7", "value7"); - TItem& item = map.Add("key8", "value8"); - UNIT_ASSERT_EQUAL(item.Key, "key8"); - UNIT_ASSERT_EQUAL(item.Value, "value8"); -} template <typename T> static void EmptyAndInsertTest(typename T::value_type v) { @@ -889,31 +889,31 @@ void THashTest::TestInsertCopy() { void THashTest::TestEmplace() { using hash_t = THashMap<int, TNonCopyableInt<0>>; - hash_t hash; + hash_t hash; hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); auto it = hash.find(1); UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); } -void THashTest::TestEmplaceNoresize() { +void THashTest::TestEmplaceNoresize() { using hash_t = THashMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash.reserve(1); - hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - -void THashTest::TestEmplaceDirect() { + hash_t hash; + hash.reserve(1); + hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + +void THashTest::TestEmplaceDirect() { using hash_t = THashMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash_t::insert_ctx ins; - hash.find(1, ins); - hash.emplace_direct(ins, std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - + hash_t hash; + hash_t::insert_ctx ins; + hash.find(1, ins); + hash.emplace_direct(ins, std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + void THashTest::TestTryEmplace() { static unsigned counter = 0u; @@ -980,59 +980,59 @@ void THashTest::TestTryEmplaceCopyKey() { } } -void THashTest::TestHMMapEmplace() { +void THashTest::TestHMMapEmplace() { using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - -void THashTest::TestHMMapEmplaceNoresize() { + hash_t hash; + hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + +void THashTest::TestHMMapEmplaceNoresize() { using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash.reserve(1); - hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - -void THashTest::TestHMMapEmplaceDirect() { + hash_t hash; + hash.reserve(1); + hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + +void THashTest::TestHMMapEmplaceDirect() { using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash_t::insert_ctx ins; - hash.find(1, ins); - hash.emplace_direct(ins, std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - + hash_t hash; + hash_t::insert_ctx ins; + hash.find(1, ins); + hash.emplace_direct(ins, std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + void THashTest::TestHSetEmplace() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; - hash_t hash; + hash_t hash; UNIT_ASSERT(!hash.contains(0)); hash.emplace(0); UNIT_ASSERT(hash.contains(0)); UNIT_ASSERT(!hash.contains(1)); -} - -void THashTest::TestHSetEmplaceNoresize() { +} + +void THashTest::TestHSetEmplaceNoresize() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; - hash_t hash; - hash.reserve(1); + hash_t hash; + hash.reserve(1); UNIT_ASSERT(!hash.contains(0)); hash.emplace_noresize(0); UNIT_ASSERT(hash.contains(0)); UNIT_ASSERT(!hash.contains(1)); } -void THashTest::TestHSetEmplaceDirect() { +void THashTest::TestHSetEmplaceDirect() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; - hash_t hash; + hash_t hash; UNIT_ASSERT(!hash.contains(0)); - hash_t::insert_ctx ins; - hash.find(0, ins); - hash.emplace_direct(ins, 1); + hash_t::insert_ctx ins; + hash.find(0, ins); + hash.emplace_direct(ins, 1); UNIT_ASSERT(hash.contains(0)); UNIT_ASSERT(!hash.contains(1)); } diff --git a/util/generic/object_counter.h b/util/generic/object_counter.h index fa0575225e..5257afa2e6 100644 --- a/util/generic/object_counter.h +++ b/util/generic/object_counter.h @@ -42,7 +42,7 @@ public: * \returns Current object count. */ static inline long ResetObjectCount() noexcept { - return AtomicSwap(&Count_, 0); + return AtomicSwap(&Count_, 0); } private: diff --git a/util/generic/singleton.h b/util/generic/singleton.h index cf4795ead4..f5fa047f5c 100644 --- a/util/generic/singleton.h +++ b/util/generic/singleton.h @@ -54,7 +54,7 @@ namespace NPrivate { UnlockRecursive(lock); - return ret; + return ret; } template <class T, size_t P, class... TArgs> diff --git a/util/system/atomic.h b/util/system/atomic.h index 0de0ad3d54..80265babfd 100644 --- a/util/system/atomic.h +++ b/util/system/atomic.h @@ -2,8 +2,8 @@ #include "defaults.h" -using TAtomicBase = intptr_t; -using TAtomic = volatile TAtomicBase; +using TAtomicBase = intptr_t; +using TAtomic = volatile TAtomicBase; #if defined(__GNUC__) #include "atomic_gcc.h" diff --git a/util/system/atomic_gcc.h b/util/system/atomic_gcc.h index 39d3987fdf..ed8dc2bdc5 100644 --- a/util/system/atomic_gcc.h +++ b/util/system/atomic_gcc.h @@ -5,32 +5,32 @@ : \ : "memory") -static inline TAtomicBase AtomicGet(const TAtomic& a) { - TAtomicBase tmp; +static inline TAtomicBase AtomicGet(const TAtomic& a) { + TAtomicBase tmp; #if defined(_arm64_) - __asm__ __volatile__( - "ldar %x[value], %[ptr] \n\t" - : [value] "=r"(tmp) - : [ptr] "Q"(a) - : "memory"); + __asm__ __volatile__( + "ldar %x[value], %[ptr] \n\t" + : [value] "=r"(tmp) + : [ptr] "Q"(a) + : "memory"); #else - __atomic_load(&a, &tmp, __ATOMIC_ACQUIRE); + __atomic_load(&a, &tmp, __ATOMIC_ACQUIRE); #endif - return tmp; -} - -static inline void AtomicSet(TAtomic& a, TAtomicBase v) { + return tmp; +} + +static inline void AtomicSet(TAtomic& a, TAtomicBase v) { #if defined(_arm64_) - __asm__ __volatile__( - "stlr %x[value], %[ptr] \n\t" - : [ptr] "=Q"(a) - : [value] "r"(v) - : "memory"); -#else - __atomic_store(&a, &v, __ATOMIC_RELEASE); -#endif + __asm__ __volatile__( + "stlr %x[value], %[ptr] \n\t" + : [ptr] "=Q"(a) + : [value] "r"(v) + : "memory"); +#else + __atomic_store(&a, &v, __ATOMIC_RELEASE); +#endif } - + static inline intptr_t AtomicIncrement(TAtomic& p) { return __atomic_add_fetch(&p, 1, __ATOMIC_SEQ_CST); } @@ -55,7 +55,7 @@ static inline intptr_t AtomicGetAndAdd(TAtomic& p, intptr_t v) { return __atomic_fetch_add(&p, v, __ATOMIC_SEQ_CST); } -static inline intptr_t AtomicSwap(TAtomic* p, intptr_t v) { +static inline intptr_t AtomicSwap(TAtomic* p, intptr_t v) { (void)p; // disable strange 'parameter set but not used' warning on gcc intptr_t ret; __atomic_exchange(p, &v, &ret, __ATOMIC_SEQ_CST); diff --git a/util/system/atomic_ops.h b/util/system/atomic_ops.h index 46a4a3a4ab..76766b4a0a 100644 --- a/util/system/atomic_ops.h +++ b/util/system/atomic_ops.h @@ -1,20 +1,20 @@ #pragma once -#include <util/generic/typetraits.h> - -template <typename T> -inline TAtomic* AsAtomicPtr(T volatile* target) { - return reinterpret_cast<TAtomic*>(target); -} - -template <typename T> -inline const TAtomic* AsAtomicPtr(T const volatile* target) { - return reinterpret_cast<const TAtomic*>(target); -} - -// integral types - -template <typename T> +#include <util/generic/typetraits.h> + +template <typename T> +inline TAtomic* AsAtomicPtr(T volatile* target) { + return reinterpret_cast<TAtomic*>(target); +} + +template <typename T> +inline const TAtomic* AsAtomicPtr(T const volatile* target) { + return reinterpret_cast<const TAtomic*>(target); +} + +// integral types + +template <typename T> struct TAtomicTraits { enum { Castable = std::is_integral<T>::value && sizeof(T) == sizeof(TAtomicBase) && !std::is_const<T>::value, @@ -25,18 +25,18 @@ template <typename T, typename TT> using TEnableIfCastable = std::enable_if_t<TAtomicTraits<T>::Castable, TT>; template <typename T> -inline TEnableIfCastable<T, T> AtomicGet(T const volatile& target) { - return static_cast<T>(AtomicGet(*AsAtomicPtr(&target))); +inline TEnableIfCastable<T, T> AtomicGet(T const volatile& target) { + return static_cast<T>(AtomicGet(*AsAtomicPtr(&target))); } template <typename T> -inline TEnableIfCastable<T, void> AtomicSet(T volatile& target, TAtomicBase value) { - AtomicSet(*AsAtomicPtr(&target), value); +inline TEnableIfCastable<T, void> AtomicSet(T volatile& target, TAtomicBase value) { + AtomicSet(*AsAtomicPtr(&target), value); } template <typename T> -inline TEnableIfCastable<T, T> AtomicIncrement(T volatile& target) { - return static_cast<T>(AtomicIncrement(*AsAtomicPtr(&target))); +inline TEnableIfCastable<T, T> AtomicIncrement(T volatile& target) { + return static_cast<T>(AtomicIncrement(*AsAtomicPtr(&target))); } template <typename T> @@ -45,8 +45,8 @@ inline TEnableIfCastable<T, T> AtomicGetAndIncrement(T volatile& target) { } template <typename T> -inline TEnableIfCastable<T, T> AtomicDecrement(T volatile& target) { - return static_cast<T>(AtomicDecrement(*AsAtomicPtr(&target))); +inline TEnableIfCastable<T, T> AtomicDecrement(T volatile& target) { + return static_cast<T>(AtomicDecrement(*AsAtomicPtr(&target))); } template <typename T> @@ -55,8 +55,8 @@ inline TEnableIfCastable<T, T> AtomicGetAndDecrement(T volatile& target) { } template <typename T> -inline TEnableIfCastable<T, T> AtomicAdd(T volatile& target, TAtomicBase value) { - return static_cast<T>(AtomicAdd(*AsAtomicPtr(&target), value)); +inline TEnableIfCastable<T, T> AtomicAdd(T volatile& target, TAtomicBase value) { + return static_cast<T>(AtomicAdd(*AsAtomicPtr(&target), value)); } template <typename T> @@ -65,8 +65,8 @@ inline TEnableIfCastable<T, T> AtomicGetAndAdd(T volatile& target, TAtomicBase v } template <typename T> -inline TEnableIfCastable<T, T> AtomicSub(T volatile& target, TAtomicBase value) { - return static_cast<T>(AtomicSub(*AsAtomicPtr(&target), value)); +inline TEnableIfCastable<T, T> AtomicSub(T volatile& target, TAtomicBase value) { + return static_cast<T>(AtomicSub(*AsAtomicPtr(&target), value)); } template <typename T> @@ -75,12 +75,12 @@ inline TEnableIfCastable<T, T> AtomicGetAndSub(T volatile& target, TAtomicBase v } template <typename T> -inline TEnableIfCastable<T, T> AtomicSwap(T volatile* target, TAtomicBase exchange) { - return static_cast<T>(AtomicSwap(AsAtomicPtr(target), exchange)); +inline TEnableIfCastable<T, T> AtomicSwap(T volatile* target, TAtomicBase exchange) { + return static_cast<T>(AtomicSwap(AsAtomicPtr(target), exchange)); } template <typename T> -inline TEnableIfCastable<T, bool> AtomicCas(T volatile* target, TAtomicBase exchange, TAtomicBase compare) { +inline TEnableIfCastable<T, bool> AtomicCas(T volatile* target, TAtomicBase exchange, TAtomicBase compare) { return AtomicCas(AsAtomicPtr(target), exchange, compare); } @@ -90,12 +90,12 @@ inline TEnableIfCastable<T, T> AtomicGetAndCas(T volatile* target, TAtomicBase e } template <typename T> -inline TEnableIfCastable<T, bool> AtomicTryLock(T volatile* target) { +inline TEnableIfCastable<T, bool> AtomicTryLock(T volatile* target) { return AtomicTryLock(AsAtomicPtr(target)); } template <typename T> -inline TEnableIfCastable<T, bool> AtomicTryAndTryLock(T volatile* target) { +inline TEnableIfCastable<T, bool> AtomicTryAndTryLock(T volatile* target) { return AtomicTryAndTryLock(AsAtomicPtr(target)); } @@ -103,85 +103,85 @@ template <typename T> inline TEnableIfCastable<T, void> AtomicUnlock(T volatile* target) { AtomicUnlock(AsAtomicPtr(target)); } - -template <typename T> -inline TEnableIfCastable<T, T> AtomicOr(T volatile& target, TAtomicBase value) { - return static_cast<T>(AtomicOr(*AsAtomicPtr(&target), value)); -} - -template <typename T> -inline TEnableIfCastable<T, T> AtomicAnd(T volatile& target, TAtomicBase value) { - return static_cast<T>(AtomicAnd(*AsAtomicPtr(&target), value)); -} - + +template <typename T> +inline TEnableIfCastable<T, T> AtomicOr(T volatile& target, TAtomicBase value) { + return static_cast<T>(AtomicOr(*AsAtomicPtr(&target), value)); +} + +template <typename T> +inline TEnableIfCastable<T, T> AtomicAnd(T volatile& target, TAtomicBase value) { + return static_cast<T>(AtomicAnd(*AsAtomicPtr(&target), value)); +} + template <typename T> inline TEnableIfCastable<T, T> AtomicXor(T volatile& target, TAtomicBase value) { return static_cast<T>(AtomicXor(*AsAtomicPtr(&target), value)); } -// pointer types - -template <typename T> -inline T* AtomicGet(T* const volatile& target) { - return reinterpret_cast<T*>(AtomicGet(*AsAtomicPtr(&target))); -} - -template <typename T> -inline void AtomicSet(T* volatile& target, T* value) { - AtomicSet(*AsAtomicPtr(&target), reinterpret_cast<TAtomicBase>(value)); -} - +// pointer types + +template <typename T> +inline T* AtomicGet(T* const volatile& target) { + return reinterpret_cast<T*>(AtomicGet(*AsAtomicPtr(&target))); +} + +template <typename T> +inline void AtomicSet(T* volatile& target, T* value) { + AtomicSet(*AsAtomicPtr(&target), reinterpret_cast<TAtomicBase>(value)); +} + using TNullPtr = decltype(nullptr); -template <typename T> +template <typename T> inline void AtomicSet(T* volatile& target, TNullPtr) { - AtomicSet(*AsAtomicPtr(&target), 0); -} - -template <typename T> -inline T* AtomicSwap(T* volatile* target, T* exchange) { - return reinterpret_cast<T*>(AtomicSwap(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange))); -} - -template <typename T> + AtomicSet(*AsAtomicPtr(&target), 0); +} + +template <typename T> +inline T* AtomicSwap(T* volatile* target, T* exchange) { + return reinterpret_cast<T*>(AtomicSwap(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange))); +} + +template <typename T> inline T* AtomicSwap(T* volatile* target, TNullPtr) { - return reinterpret_cast<T*>(AtomicSwap(AsAtomicPtr(target), 0)); -} - -template <typename T> -inline bool AtomicCas(T* volatile* target, T* exchange, T* compare) { - return AtomicCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), reinterpret_cast<TAtomicBase>(compare)); -} - -template <typename T> + return reinterpret_cast<T*>(AtomicSwap(AsAtomicPtr(target), 0)); +} + +template <typename T> +inline bool AtomicCas(T* volatile* target, T* exchange, T* compare) { + return AtomicCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), reinterpret_cast<TAtomicBase>(compare)); +} + +template <typename T> inline T* AtomicGetAndCas(T* volatile* target, T* exchange, T* compare) { return reinterpret_cast<T*>(AtomicGetAndCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), reinterpret_cast<TAtomicBase>(compare))); } template <typename T> inline bool AtomicCas(T* volatile* target, T* exchange, TNullPtr) { - return AtomicCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), 0); -} - -template <typename T> + return AtomicCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), 0); +} + +template <typename T> inline T* AtomicGetAndCas(T* volatile* target, T* exchange, TNullPtr) { return reinterpret_cast<T*>(AtomicGetAndCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), 0)); } template <typename T> inline bool AtomicCas(T* volatile* target, TNullPtr, T* compare) { - return AtomicCas(AsAtomicPtr(target), 0, reinterpret_cast<TAtomicBase>(compare)); -} - -template <typename T> + return AtomicCas(AsAtomicPtr(target), 0, reinterpret_cast<TAtomicBase>(compare)); +} + +template <typename T> inline T* AtomicGetAndCas(T* volatile* target, TNullPtr, T* compare) { return reinterpret_cast<T*>(AtomicGetAndCas(AsAtomicPtr(target), 0, reinterpret_cast<TAtomicBase>(compare))); } template <typename T> inline bool AtomicCas(T* volatile* target, TNullPtr, TNullPtr) { - return AtomicCas(AsAtomicPtr(target), 0, 0); -} + return AtomicCas(AsAtomicPtr(target), 0, 0); +} template <typename T> inline T* AtomicGetAndCas(T* volatile* target, TNullPtr, TNullPtr) { diff --git a/util/system/atomic_ut.cpp b/util/system/atomic_ut.cpp index c53722766a..07211ffba7 100644 --- a/util/system/atomic_ut.cpp +++ b/util/system/atomic_ut.cpp @@ -145,13 +145,13 @@ private: inline void TestAtomicSwap() { TAtomic v = 0; - UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, 3), 0); - UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, 5), 3); - UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, -7), 5); - UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, Max<intptr_t>()), -7); + UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, 3), 0); + UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, 5), 3); + UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, -7), 5); + UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, Max<intptr_t>()), -7); UNIT_ASSERT_VALUES_EQUAL(v, Max<intptr_t>()); } - + inline void TestAtomicOr() { TAtomic v = 0xf0; @@ -173,19 +173,19 @@ private: UNIT_ASSERT_VALUES_EQUAL(AtomicXor(v, 0xff), 0x00); } - inline void TestAtomicPtr() { - int* p; + inline void TestAtomicPtr() { + int* p; AtomicSet(p, nullptr); - - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(p), 0); - - int i; - AtomicSet(p, &i); - - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(p), &i); + + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(p), 0); + + int i; + AtomicSet(p, &i); + + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(p), &i); UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&p, nullptr), &i); UNIT_ASSERT(AtomicCas(&p, &i, nullptr)); - } + } }; UNIT_TEST_SUITE_REGISTRATION(TAtomicTest<TAtomic>); diff --git a/util/system/atomic_win.h b/util/system/atomic_win.h index 124abbc698..65c290e6cc 100644 --- a/util/system/atomic_win.h +++ b/util/system/atomic_win.h @@ -2,8 +2,8 @@ #include <intrin.h> -#define USE_GENERIC_SETGET - +#define USE_GENERIC_SETGET + #if defined(_i386_) #pragma intrinsic(_InterlockedIncrement) @@ -36,8 +36,8 @@ static inline intptr_t AtomicGetAndAdd(TAtomic& a, intptr_t b) { return _InterlockedExchangeAdd((volatile long*)&a, b); } -static inline intptr_t AtomicSwap(TAtomic* a, intptr_t b) { - return _InterlockedExchange((volatile long*)a, b); +static inline intptr_t AtomicSwap(TAtomic* a, intptr_t b) { + return _InterlockedExchange((volatile long*)a, b); } static inline bool AtomicCas(TAtomic* a, intptr_t exchange, intptr_t compare) { @@ -80,8 +80,8 @@ static inline intptr_t AtomicGetAndAdd(TAtomic& a, intptr_t b) { return _InterlockedExchangeAdd64((volatile __int64*)&a, b); } -static inline intptr_t AtomicSwap(TAtomic* a, intptr_t b) { - return _InterlockedExchange64((volatile __int64*)a, b); +static inline intptr_t AtomicSwap(TAtomic* a, intptr_t b) { + return _InterlockedExchange64((volatile __int64*)a, b); } static inline bool AtomicCas(TAtomic* a, intptr_t exchange, intptr_t compare) { @@ -110,5 +110,5 @@ static inline intptr_t AtomicXor(TAtomic& a, intptr_t b) { static inline void AtomicBarrier() { TAtomic val = 0; - AtomicSwap(&val, 0); + AtomicSwap(&val, 0); } diff --git a/util/system/sanitizers.cpp b/util/system/sanitizers.cpp index b17e60a094..bb799a9e2e 100644 --- a/util/system/sanitizers.cpp +++ b/util/system/sanitizers.cpp @@ -1,4 +1,4 @@ -#include "sanitizers.h" +#include "sanitizers.h" #include "thread.h" #if defined(_asan_enabled_) diff --git a/util/system/sanitizers.h b/util/system/sanitizers.h index b7d5a72f6f..965e5c751e 100644 --- a/util/system/sanitizers.h +++ b/util/system/sanitizers.h @@ -1,22 +1,22 @@ #pragma once -#include "defaults.h" +#include "defaults.h" + +extern "C" { // sanitizers API -extern "C" { // sanitizers API - #if defined(_asan_enabled_) void __lsan_ignore_object(const void* p); #endif -#if defined(_msan_enabled_) +#if defined(_msan_enabled_) void __msan_unpoison(const volatile void* a, size_t size); void __msan_poison(const volatile void* a, size_t size); void __msan_check_mem_is_initialized(const volatile void* x, size_t size); #endif -}; // sanitizers API - -namespace NSan { +}; // sanitizers API + +namespace NSan { class TFiberContext { public: TFiberContext() noexcept; @@ -54,63 +54,63 @@ namespace NSan { #endif } - // Determines if asan present + // Determines if asan present inline constexpr static bool ASanIsOn() noexcept { -#if defined(_asan_enabled_) - return true; -#else - return false; +#if defined(_asan_enabled_) + return true; +#else + return false; #endif - } + } - // Determines if tsan present + // Determines if tsan present inline constexpr static bool TSanIsOn() noexcept { -#if defined(_tsan_enabled_) - return true; -#else - return false; +#if defined(_tsan_enabled_) + return true; +#else + return false; #endif - } + } - // Determines if msan present + // Determines if msan present inline constexpr static bool MSanIsOn() noexcept { -#if defined(_msan_enabled_) - return true; -#else - return false; +#if defined(_msan_enabled_) + return true; +#else + return false; #endif - } + } - // Make memory region fully initialized (without changing its contents). + // Make memory region fully initialized (without changing its contents). inline static void Unpoison(const volatile void* a, size_t size) noexcept { -#if defined(_msan_enabled_) - __msan_unpoison(a, size); -#else - Y_UNUSED(a); - Y_UNUSED(size); -#endif - } - - // Make memory region fully uninitialized (without changing its contents). - // This is a legacy interface that does not update origin information. Use __msan_allocated_memory() instead. +#if defined(_msan_enabled_) + __msan_unpoison(a, size); +#else + Y_UNUSED(a); + Y_UNUSED(size); +#endif + } + + // Make memory region fully uninitialized (without changing its contents). + // This is a legacy interface that does not update origin information. Use __msan_allocated_memory() instead. inline static void Poison(const volatile void* a, size_t size) noexcept { -#if defined(_msan_enabled_) - __msan_poison(a, size); +#if defined(_msan_enabled_) + __msan_poison(a, size); #else - Y_UNUSED(a); - Y_UNUSED(size); + Y_UNUSED(a); + Y_UNUSED(size); #endif - } + } - // Checks that memory range is fully initialized, and reports an error if it is not. + // Checks that memory range is fully initialized, and reports an error if it is not. inline static void CheckMemIsInitialized(const volatile void* a, size_t size) noexcept { -#if defined(_msan_enabled_) - __msan_check_mem_is_initialized(a, size); +#if defined(_msan_enabled_) + __msan_check_mem_is_initialized(a, size); #else - Y_UNUSED(a); - Y_UNUSED(size); + Y_UNUSED(a); + Y_UNUSED(size); #endif - } + } inline static void MarkAsIntentionallyLeaked(const void* ptr) noexcept { #if defined(_asan_enabled_) diff --git a/util/system/sem.cpp b/util/system/sem.cpp index 5ce3b1e529..4a93b903b5 100644 --- a/util/system/sem.cpp +++ b/util/system/sem.cpp @@ -133,8 +133,8 @@ namespace { #endif } - //The UNIX semaphore object does not support a timed "wait", and - //hence to maintain consistancy, for win32 case we use INFINITE or 0 timeout. + //The UNIX semaphore object does not support a timed "wait", and + //hence to maintain consistancy, for win32 case we use INFINITE or 0 timeout. inline void Acquire() noexcept { #ifdef _win_ Y_VERIFY(::WaitForSingleObject(Handle, INFINITE) == WAIT_OBJECT_0, "can not acquire semaphore"); @@ -154,7 +154,7 @@ namespace { // zero-second time-out interval // WAIT_OBJECT_0: current free count > 0 // WAIT_TIMEOUT: current free count == 0 - return ::WaitForSingleObject(Handle, 0) == WAIT_OBJECT_0; + return ::WaitForSingleObject(Handle, 0) == WAIT_OBJECT_0; #else #ifdef USE_SYSV_SEMAPHORES struct sembuf ops[] = {{0, -1, SEM_UNDO | IPC_NOWAIT}}; diff --git a/util/system/spinlock.h b/util/system/spinlock.h index cd8c6f26a3..af2630890a 100644 --- a/util/system/spinlock.h +++ b/util/system/spinlock.h @@ -27,13 +27,13 @@ protected: }; static inline void SpinLockPause() { -#if defined(__GNUC__) - #if defined(_i386_) || defined(_x86_64_) +#if defined(__GNUC__) + #if defined(_i386_) || defined(_x86_64_) __asm __volatile("pause"); - #elif defined(_arm64_) - __asm __volatile("yield" :: - : "memory"); - #endif + #elif defined(_arm64_) + __asm __volatile("yield" :: + : "memory"); + #endif #endif } diff --git a/util/thread/lfstack.h b/util/thread/lfstack.h index cfd9e3aef5..ca3d95f3c3 100644 --- a/util/thread/lfstack.h +++ b/util/thread/lfstack.h @@ -21,12 +21,12 @@ class TLockFreeStack: TNonCopyable { } }; - TNode* Head; - TNode* FreePtr; + TNode* Head; + TNode* FreePtr; TAtomic DequeueCount; void TryToFreeMemory() { - TNode* current = AtomicGet(FreePtr); + TNode* current = AtomicGet(FreePtr); if (!current) return; if (AtomicAdd(DequeueCount, 0) == 1) { @@ -44,7 +44,7 @@ class TLockFreeStack: TNonCopyable { } void EnqueueImpl(TNode* volatile head, TNode* volatile tail) { for (;;) { - tail->Next = AtomicGet(Head); + tail->Next = AtomicGet(Head); if (AtomicCas(&Head, head, tail->Next)) break; } @@ -97,7 +97,7 @@ public: } bool Dequeue(T* res) { AtomicAdd(DequeueCount, 1); - for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { + for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { if (AtomicCas(&Head, AtomicGet(current->Next), current)) { *res = std::move(current->Value); // delete current; // ABA problem @@ -126,7 +126,7 @@ public: template <typename TCollection> void DequeueAll(TCollection* res) { AtomicAdd(DequeueCount, 1); - for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { + for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { if (AtomicCas(&Head, (TNode*)nullptr, current)) { for (TNode* x = current; x;) { res->push_back(std::move(x->Value)); @@ -157,7 +157,7 @@ public: AtomicAdd(DequeueCount, -1); } bool DequeueSingleConsumer(T* res) { - for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { + for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { if (AtomicCas(&Head, current->Next, current)) { *res = std::move(current->Value); delete current; // with single consumer thread ABA does not happen @@ -170,7 +170,7 @@ public: // elements are returned in order of dequeue (top to bottom; see example in unittest) template <typename TCollection> void DequeueAllSingleConsumer(TCollection* res) { - for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { + for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { if (AtomicCas(&Head, (TNode*)nullptr, current)) { for (TNode* x = current; x;) { res->push_back(std::move(x->Value)); @@ -183,6 +183,6 @@ public: } bool IsEmpty() { AtomicAdd(DequeueCount, 0); // mem barrier - return AtomicGet(Head) == nullptr; // without lock, so result is approximate + return AtomicGet(Head) == nullptr; // without lock, so result is approximate } }; diff --git a/util/ya.make b/util/ya.make index 520dfba2e6..6ebe7e40cf 100644 --- a/util/ya.make +++ b/util/ya.make @@ -303,7 +303,7 @@ JOIN_SRCS( system/protect.cpp system/rusage.cpp system/rwlock.cpp - system/sanitizers.cpp + system/sanitizers.cpp system/sem.cpp system/shellcommand.cpp system/shmat.cpp diff --git a/ydb/core/base/blobstorage.h b/ydb/core/base/blobstorage.h index 8654f0707a..a2faee326e 100644 --- a/ydb/core/base/blobstorage.h +++ b/ydb/core/base/blobstorage.h @@ -393,8 +393,8 @@ public: }; inline TActorId TTabletStorageInfo::BSProxyIDForChannel(ui32 channel, ui32 generation) const { - const ui32 group = GroupFor(channel, generation); - Y_VERIFY(group != Max<ui32>()); + const ui32 group = GroupFor(channel, generation); + Y_VERIFY(group != Max<ui32>()); const TActorId proxy = MakeBlobStorageProxyID(group); return proxy; } diff --git a/ydb/core/base/events.h b/ydb/core/base/events.h index 2038f20224..f5fedfe19b 100644 --- a/ydb/core/base/events.h +++ b/ydb/core/base/events.h @@ -118,8 +118,8 @@ struct TKikimrEvents : TEvents { ES_BLOCKSTORE_PRIVATE, ES_YT_WRAPPER, ES_S3_WRAPPER, - ES_FILESTORE, - ES_FILESTORE_PRIVATE, + ES_FILESTORE, + ES_FILESTORE_PRIVATE, ES_YDB_METERING, ES_IMPORT_SERVICE, // 4200 ES_TX_OLAPSHARD, diff --git a/ydb/core/base/pool_stats_collector.cpp b/ydb/core/base/pool_stats_collector.cpp index 3b296587c9..7dcbf28954 100644 --- a/ydb/core/base/pool_stats_collector.cpp +++ b/ydb/core/base/pool_stats_collector.cpp @@ -1,14 +1,14 @@ -#include "pool_stats_collector.h" - -#include "counters.h" - +#include "pool_stats_collector.h" + +#include "counters.h" + #include <ydb/core/node_whiteboard/node_whiteboard.h> - + #include <ydb/library/yql/minikql/aligned_page_pool.h> - + #include <library/cpp/actors/core/actor_bootstrapped.h> #include <library/cpp/actors/helpers/pool_stats_collector.h> - + namespace NKikimr { // Periodically collects stats from executor threads and exposes them as mon counters @@ -63,4 +63,4 @@ IActor *CreateStatsCollector(ui32 intervalSec, return new TStatsCollectingActor(intervalSec, setup, counters); } -} // namespace NKikimr +} // namespace NKikimr diff --git a/ydb/core/base/tablet_types.h b/ydb/core/base/tablet_types.h index 318f29971e..f585819299 100644 --- a/ydb/core/base/tablet_types.h +++ b/ydb/core/base/tablet_types.h @@ -29,15 +29,15 @@ public: static constexpr EType NODE_BROKER = NodeBroker; static constexpr EType CMS = Cms; static constexpr EType RTMR_PARTITION = RTMRPartition; - static constexpr EType BLOCKSTORE_VOLUME = BlockStoreVolume; - static constexpr EType BLOCKSTORE_PARTITION = BlockStorePartition; + static constexpr EType BLOCKSTORE_VOLUME = BlockStoreVolume; + static constexpr EType BLOCKSTORE_PARTITION = BlockStorePartition; static constexpr EType BLOCKSTORE_PARTITION2 = BlockStorePartition2; - static constexpr EType BLOCKSTORE_DISK_REGISTRY = BlockStoreDiskRegistry; + static constexpr EType BLOCKSTORE_DISK_REGISTRY = BlockStoreDiskRegistry; static constexpr EType TENANT_SLOT_BROKER = TenantSlotBroker; static constexpr EType CONSOLE = Console; static constexpr EType KESUS = Kesus; static constexpr EType SYS_VIEW_PROCESSOR = SysViewProcessor; - static constexpr EType FILESTORE = FileStore; + static constexpr EType FILESTORE = FileStore; static constexpr EType TESTSHARD = TestShard; static constexpr EType SEQUENCESHARD = SequenceShard; static constexpr EType REPLICATION_CONTROLLER = ReplicationController; diff --git a/ydb/core/blobstorage/dsproxy/ut_fat/dsproxy_ut.cpp b/ydb/core/blobstorage/dsproxy/ut_fat/dsproxy_ut.cpp index a114c8cf6a..13b1bec356 100644 --- a/ydb/core/blobstorage/dsproxy/ut_fat/dsproxy_ut.cpp +++ b/ydb/core/blobstorage/dsproxy/ut_fat/dsproxy_ut.cpp @@ -16,7 +16,7 @@ #include <ydb/core/base/tablet.h> #include <ydb/core/mon_alloc/profiler.h> - + #include <ydb/core/protos/blobstorage_pdisk_config.pb.h> #include <ydb/core/protos/blobstorage_vdisk_config.pb.h> #include <ydb/core/protos/services.pb.h> diff --git a/ydb/core/blobstorage/vdisk/common/vdisk_events.h b/ydb/core/blobstorage/vdisk/common/vdisk_events.h index 89ff56a3ac..47fbd959c9 100644 --- a/ydb/core/blobstorage/vdisk/common/vdisk_events.h +++ b/ydb/core/blobstorage/vdisk/common/vdisk_events.h @@ -398,22 +398,22 @@ namespace NKikimr { NWilson::TTraceId TraceId; }; - template<typename TEv, typename TRecord /*protobuf record*/, ui32 TEventType> + template<typename TEv, typename TRecord /*protobuf record*/, ui32 TEventType> class TEvVResultBasePB : public TEventPB<TEv, TRecord, TEventType> , public TEvVResultBase { using TEventPBBase = TEventPB<TEv, TRecord, TEventType>; - public: + public: TEvVResultBasePB() = default; - + TEvVResultBasePB(const TInstant &now, const NMonitoring::TDynamicCounters::TCounterPtr &counterPtr, const NVDiskMon::TLtcHistoPtr &histoPtr, NWilson::TTraceId traceId, ui32 channel) : TEvVResultBase(now, channel, counterPtr, histoPtr, std::move(traceId)) - {} - }; - + {} + }; + template<typename TEv, typename TRecord /*protobuf record*/, ui32 TEventType> class TEvVResultBaseWithQoSPB : public TEvVResultBasePB<TEv, TRecord, TEventType> { using TBase = TEvVResultBasePB<TEv, TRecord, TEventType>; diff --git a/ydb/core/blockstore/core/blockstore.h b/ydb/core/blockstore/core/blockstore.h index 4eb22a3935..bce840973f 100644 --- a/ydb/core/blockstore/core/blockstore.h +++ b/ydb/core/blockstore/core/blockstore.h @@ -9,11 +9,11 @@ namespace NKikimr { struct TEvBlockStore { enum EEv { - EvBegin = EventSpaceBegin(TKikimrEvents::ES_BLOCKSTORE) + 1011, - - EvUpdateVolumeConfig = EvBegin + 13, + EvBegin = EventSpaceBegin(TKikimrEvents::ES_BLOCKSTORE) + 1011, + + EvUpdateVolumeConfig = EvBegin + 13, EvUpdateVolumeConfigResponse, - + EvEnd }; diff --git a/ydb/core/driver_lib/run/kikimr_services_initializers.cpp b/ydb/core/driver_lib/run/kikimr_services_initializers.cpp index 2d972fe820..819c1478d1 100644 --- a/ydb/core/driver_lib/run/kikimr_services_initializers.cpp +++ b/ydb/core/driver_lib/run/kikimr_services_initializers.cpp @@ -77,7 +77,7 @@ #include <ydb/core/mon_alloc/monitor.h> #include <ydb/core/mon_alloc/profiler.h> #include <ydb/core/mon_alloc/stats.h> - + #include <ydb/core/node_whiteboard/node_whiteboard.h> #include <ydb/core/persqueue/cluster_tracker.h> @@ -1016,11 +1016,11 @@ void TBlobCacheInitializer::InitializeServices( // TLoggerInitializer TLoggerInitializer::TLoggerInitializer(const TKikimrRunConfig& runConfig, - TIntrusivePtr<NActors::NLog::TSettings> logSettings, - std::shared_ptr<TLogBackend> logBackend) + TIntrusivePtr<NActors::NLog::TSettings> logSettings, + std::shared_ptr<TLogBackend> logBackend) : IKikimrServicesInitializer(runConfig) - , LogSettings(logSettings) - , LogBackend(logBackend) + , LogSettings(logSettings) + , LogBackend(logBackend) , PathToConfigCacheFile(runConfig.PathToConfigCacheFile) { } @@ -1031,7 +1031,7 @@ void TLoggerInitializer::InitializeServices( const TIntrusivePtr<NMonitoring::TDynamicCounters> utilsCounters = GetServiceCounters(appData->Counters, "utils"); // log settings must be initialized before calling this method - NActors::TLoggerActor *loggerActor = new NActors::TLoggerActor(LogSettings, LogBackend, utilsCounters); + NActors::TLoggerActor *loggerActor = new NActors::TLoggerActor(LogSettings, LogBackend, utilsCounters); NActors::TActorSetupCmd loggerActorCmd(loggerActor, NActors::TMailboxType::HTSwap, appData->IOPoolId); std::pair<NActors::TActorId, NActors::TActorSetupCmd> loggerActorPair(LogSettings->LoggerActorId, loggerActorCmd); setup->LocalServices.push_back(loggerActorPair); @@ -1075,7 +1075,7 @@ void TProfilerInitializer::InitializeServices( const NKikimr::TAppData* appData) { const TIntrusivePtr<NMonitoring::TDynamicCounters> utilsCounters = GetServiceCounters(appData->Counters, "utils"); - TActorSetupCmd profilerSetup(CreateProfilerActor(utilsCounters, "/var/tmp"), TMailboxType::HTSwap, 0); + TActorSetupCmd profilerSetup(CreateProfilerActor(utilsCounters, "/var/tmp"), TMailboxType::HTSwap, 0); setup->LocalServices.push_back(std::pair<TActorId, TActorSetupCmd>(MakeProfilerID(NodeId), profilerSetup)); } @@ -1632,38 +1632,38 @@ TStatsCollectorInitializer::TStatsCollectorInitializer(const TKikimrRunConfig& r void TStatsCollectorInitializer::InitializeServices( NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) { - + if (appData->Mon) { IActor* statsCollector = CreateStatsCollector( 1, // seconds *setup, appData->Counters); - setup->LocalServices.emplace_back( + setup->LocalServices.emplace_back( TActorId(), - TActorSetupCmd( - statsCollector, - TMailboxType::HTSwap, - appData->UserPoolId)); - - IActor* memStatsCollector = CreateMemStatsCollector( - 1, // seconds - appData->Counters); - setup->LocalServices.emplace_back( + TActorSetupCmd( + statsCollector, + TMailboxType::HTSwap, + appData->UserPoolId)); + + IActor* memStatsCollector = CreateMemStatsCollector( + 1, // seconds + appData->Counters); + setup->LocalServices.emplace_back( TActorId(), - TActorSetupCmd( - memStatsCollector, - TMailboxType::HTSwap, - appData->UserPoolId)); - + TActorSetupCmd( + memStatsCollector, + TMailboxType::HTSwap, + appData->UserPoolId)); + IActor* procStatCollector = CreateProcStatCollector( 5, // seconds appData->Counters); - setup->LocalServices.emplace_back( + setup->LocalServices.emplace_back( TActorId(), - TActorSetupCmd( - procStatCollector, - TMailboxType::HTSwap, - appData->UserPoolId)); + TActorSetupCmd( + procStatCollector, + TMailboxType::HTSwap, + appData->UserPoolId)); } } #endif @@ -1861,7 +1861,7 @@ void TPersQueueClusterTrackerInitializer::InitializeServices(NActors::TActorSyst } // TPersQueueLibSharedInstanceInitializer - + TPersQueueLibSharedInstanceInitializer::TPersQueueLibSharedInstanceInitializer(const TKikimrRunConfig& runConfig) : IKikimrServicesInitializer(runConfig) {} @@ -1886,16 +1886,16 @@ void TMemProfMonitorInitializer::InitializeServices( NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) { - IActor* monitorActor = CreateMemProfMonitor( - 1, // seconds - appData->Counters); - - setup->LocalServices.emplace_back( - MakeMemProfMonitorID(NodeId), - TActorSetupCmd( - monitorActor, - TMailboxType::HTSwap, - appData->UserPoolId)); + IActor* monitorActor = CreateMemProfMonitor( + 1, // seconds + appData->Counters); + + setup->LocalServices.emplace_back( + MakeMemProfMonitorID(NodeId), + TActorSetupCmd( + monitorActor, + TMailboxType::HTSwap, + appData->UserPoolId)); } // TMemoryTrackerInitializer @@ -1914,7 +1914,7 @@ void TMemoryTrackerInitializer::InitializeServices( TActorSetupCmd(actor, TMailboxType::HTSwap, appData->UserPoolId) ); } - + TQuoterServiceInitializer::TQuoterServiceInitializer(const TKikimrRunConfig& runConfig) : IKikimrServicesInitializer(runConfig) {} diff --git a/ydb/core/driver_lib/run/kikimr_services_initializers.h b/ydb/core/driver_lib/run/kikimr_services_initializers.h index e1d50c97dd..407ce1bb7b 100644 --- a/ydb/core/driver_lib/run/kikimr_services_initializers.h +++ b/ydb/core/driver_lib/run/kikimr_services_initializers.h @@ -100,13 +100,13 @@ public: class TLoggerInitializer : public IKikimrServicesInitializer { TIntrusivePtr<NActors::NLog::TSettings> LogSettings; - std::shared_ptr<TLogBackend> LogBackend; + std::shared_ptr<TLogBackend> LogBackend; TString PathToConfigCacheFile; public: TLoggerInitializer(const TKikimrRunConfig& runConfig, - TIntrusivePtr<NActors::NLog::TSettings> logSettings, - std::shared_ptr<TLogBackend> logBackend); + TIntrusivePtr<NActors::NLog::TSettings> logSettings, + std::shared_ptr<TLogBackend> logBackend); void InitializeServices(NActors::TActorSystemSetup *setup, const NKikimr::TAppData *appData) override; }; @@ -367,7 +367,7 @@ public: class TMemoryTrackerInitializer : public IKikimrServicesInitializer { public: TMemoryTrackerInitializer(const TKikimrRunConfig& runConfig); - + void InitializeServices(NActors::TActorSystemSetup* setup, const NKikimr::TAppData* appData) override; }; diff --git a/ydb/core/driver_lib/run/run.cpp b/ydb/core/driver_lib/run/run.cpp index 75c867c692..a4f74aa4e0 100644 --- a/ydb/core/driver_lib/run/run.cpp +++ b/ydb/core/driver_lib/run/run.cpp @@ -946,7 +946,7 @@ void TKikimrRunner::InitializeLogSettings(const TKikimrRunConfig& runConfig) auto logBackend = TLogBackendFactory().CreateLogBackend(runConfig, Counters); LogBackend.reset(logBackend.Release()); } - + if (!runConfig.AppConfig.HasLogConfig()) return; @@ -1027,12 +1027,12 @@ void TKikimrRunner::ApplyLogSettings(const TKikimrRunConfig& runConfig) } } -void TKikimrRunner::InitializeActorSystem( - const TKikimrRunConfig& runConfig, - TIntrusivePtr<TServiceInitializersList> serviceInitializers, - const TBasicKikimrServicesMask& servicesMask) +void TKikimrRunner::InitializeActorSystem( + const TKikimrRunConfig& runConfig, + TIntrusivePtr<TServiceInitializersList> serviceInitializers, + const TBasicKikimrServicesMask& servicesMask) { - THolder<TActorSystemSetup> setup(new TActorSystemSetup()); + THolder<TActorSystemSetup> setup(new TActorSystemSetup()); serviceInitializers->InitializeServices(setup.Get(), AppData.Get()); @@ -1046,46 +1046,46 @@ void TKikimrRunner::InitializeActorSystem( ActorSystem.Reset(new TActorSystem(setup, AppData.Get(), LogSettings)); if (Monitoring) { - if (servicesMask.EnableLogger) { - Monitoring->RegisterActorPage( - ActorsMonPage, - "logger", - "Logger", - false, - ActorSystem.Get(), - LogSettings->LoggerActorId); - } - - if (servicesMask.EnableProfiler) { - Monitoring->RegisterActorPage( - ActorsMonPage, - "profiler", - "Profiler", - false, - ActorSystem.Get(), - MakeProfilerID(runConfig.NodeId)); - } - - if (servicesMask.EnableLoadService) { - Monitoring->RegisterActorPage( - ActorsMonPage, - "load", - "Load", - false, - ActorSystem.Get(), - MakeBlobStorageLoadID(runConfig.NodeId)); - } - - if (servicesMask.EnableFailureInjectionService) { - Monitoring->RegisterActorPage( - ActorsMonPage, - "failure_injection", - "Failure Injection", - false, - ActorSystem.Get(), - MakeBlobStorageFailureInjectionID(runConfig.NodeId)); - } - + if (servicesMask.EnableLogger) { + Monitoring->RegisterActorPage( + ActorsMonPage, + "logger", + "Logger", + false, + ActorSystem.Get(), + LogSettings->LoggerActorId); + } + + if (servicesMask.EnableProfiler) { + Monitoring->RegisterActorPage( + ActorsMonPage, + "profiler", + "Profiler", + false, + ActorSystem.Get(), + MakeProfilerID(runConfig.NodeId)); + } + + if (servicesMask.EnableLoadService) { + Monitoring->RegisterActorPage( + ActorsMonPage, + "load", + "Load", + false, + ActorSystem.Get(), + MakeBlobStorageLoadID(runConfig.NodeId)); + } + + if (servicesMask.EnableFailureInjectionService) { + Monitoring->RegisterActorPage( + ActorsMonPage, + "failure_injection", + "Failure Injection", + false, + ActorSystem.Get(), + MakeBlobStorageFailureInjectionID(runConfig.NodeId)); + } + Monitoring->Register(CreateMonGetBlobPage("get_blob", ActorSystem.Get())); Monitoring->Register(CreateMonBlobRangePage("blob_range", ActorSystem.Get())); Monitoring->Register(CreateMonVDiskStreamPage("vdisk_stream", ActorSystem.Get())); @@ -1169,7 +1169,7 @@ TIntrusivePtr<TServiceInitializersList> TKikimrRunner::CreateServiceInitializers sil->AddServiceInitializer(new TBlobCacheInitializer(runConfig)); } if (serviceMask.EnableLogger) { - sil->AddServiceInitializer(new TLoggerInitializer(runConfig, LogSettings, LogBackend)); + sil->AddServiceInitializer(new TLoggerInitializer(runConfig, LogSettings, LogBackend)); } if (serviceMask.EnableSchedulerActor) { sil->AddServiceInitializer(new TSchedulerActorInitializer(runConfig)); @@ -1358,7 +1358,7 @@ void TKikimrRunner::KikimrStart() { } ThreadSigmask(SIG_BLOCK); - if (ActorSystem) { + if (ActorSystem) { RegisterBaseTagForMemoryProfiling(ActorSystem.Get()); ActorSystem->Start(); } diff --git a/ydb/core/driver_lib/run/run.h b/ydb/core/driver_lib/run/run.h index e625314f55..dfd93a24e7 100644 --- a/ydb/core/driver_lib/run/run.h +++ b/ydb/core/driver_lib/run/run.h @@ -60,7 +60,7 @@ protected: TVector<std::pair<TString, TAutoPtr<NGrpc::TGRpcServer>>> GRpcServers; TIntrusivePtr<NActors::NLog::TSettings> LogSettings; - std::shared_ptr<TLogBackend> LogBackend; + std::shared_ptr<TLogBackend> LogBackend; TAutoPtr<TActorSystem> ActorSystem; TKikimrRunner(std::shared_ptr<TModuleFactories> factories = {}); @@ -94,14 +94,14 @@ protected: void InitializeAppData(const TKikimrRunConfig& runConfig); - void InitializeActorSystem( - const TKikimrRunConfig& runConfig, - TIntrusivePtr<TServiceInitializersList> serviceInitializers, - const TBasicKikimrServicesMask& serviceMask = {}); + void InitializeActorSystem( + const TKikimrRunConfig& runConfig, + TIntrusivePtr<TServiceInitializersList> serviceInitializers, + const TBasicKikimrServicesMask& serviceMask = {}); - TIntrusivePtr<TServiceInitializersList> CreateServiceInitializersList( - const TKikimrRunConfig& runConfig, - const TBasicKikimrServicesMask& serviceMask = {}); + TIntrusivePtr<TServiceInitializersList> CreateServiceInitializersList( + const TKikimrRunConfig& runConfig, + const TBasicKikimrServicesMask& serviceMask = {}); public: static void SetSignalHandlers(); diff --git a/ydb/core/filestore/core/filestore.cpp b/ydb/core/filestore/core/filestore.cpp index 31df124206..1add4f3a36 100644 --- a/ydb/core/filestore/core/filestore.cpp +++ b/ydb/core/filestore/core/filestore.cpp @@ -1 +1 @@ -#include "filestore.h" +#include "filestore.h" diff --git a/ydb/core/filestore/core/filestore.h b/ydb/core/filestore/core/filestore.h index 437d3970c3..130c1b2bd7 100644 --- a/ydb/core/filestore/core/filestore.h +++ b/ydb/core/filestore/core/filestore.h @@ -1,35 +1,35 @@ -#pragma once - -#include <library/cpp/actors/core/actor.h> -#include <library/cpp/actors/core/actorid.h> +#pragma once + +#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/actorid.h> #include <ydb/core/base/blobstorage.h> #include <ydb/core/protos/filestore_config.pb.h> - -namespace NKikimr { - -struct TEvFileStore { - enum EEv { - EvBegin = EventSpaceBegin(TKikimrEvents::ES_FILESTORE), - - EvUpdateConfig = EvBegin + 1, - EvUpdateConfigResponse = EvBegin + 2, - - EvEnd - }; - - static_assert( - EvEnd < EventSpaceEnd(TKikimrEvents::ES_FILESTORE), - "expect EvEnd < EventSpaceEnd(TKikimrEvents::ES_FILESTORE)"); - - struct TEvUpdateConfig : TEventPB<TEvUpdateConfig, - NKikimrFileStore::TUpdateConfig, EvUpdateConfig> { - TEvUpdateConfig() {} - }; - - struct TEvUpdateConfigResponse : TEventPB<TEvUpdateConfigResponse, - NKikimrFileStore::TUpdateConfigResponse, EvUpdateConfigResponse> { - TEvUpdateConfigResponse() {} - }; -}; - -} + +namespace NKikimr { + +struct TEvFileStore { + enum EEv { + EvBegin = EventSpaceBegin(TKikimrEvents::ES_FILESTORE), + + EvUpdateConfig = EvBegin + 1, + EvUpdateConfigResponse = EvBegin + 2, + + EvEnd + }; + + static_assert( + EvEnd < EventSpaceEnd(TKikimrEvents::ES_FILESTORE), + "expect EvEnd < EventSpaceEnd(TKikimrEvents::ES_FILESTORE)"); + + struct TEvUpdateConfig : TEventPB<TEvUpdateConfig, + NKikimrFileStore::TUpdateConfig, EvUpdateConfig> { + TEvUpdateConfig() {} + }; + + struct TEvUpdateConfigResponse : TEventPB<TEvUpdateConfigResponse, + NKikimrFileStore::TUpdateConfigResponse, EvUpdateConfigResponse> { + TEvUpdateConfigResponse() {} + }; +}; + +} diff --git a/ydb/core/filestore/core/ya.make b/ydb/core/filestore/core/ya.make index 8e1567b72c..6e660bac83 100644 --- a/ydb/core/filestore/core/ya.make +++ b/ydb/core/filestore/core/ya.make @@ -1,15 +1,15 @@ -LIBRARY() - -OWNER(g:kikimr) - -PEERDIR( - library/cpp/actors/core +LIBRARY() + +OWNER(g:kikimr) + +PEERDIR( + library/cpp/actors/core ydb/core/base ydb/core/protos -) - -SRCS( - filestore.cpp -) - -END() +) + +SRCS( + filestore.cpp +) + +END() diff --git a/ydb/core/filestore/ya.make b/ydb/core/filestore/ya.make index 2debeabc60..a9ad8235c9 100644 --- a/ydb/core/filestore/ya.make +++ b/ydb/core/filestore/ya.make @@ -1,9 +1,9 @@ -LIBRARY() - -OWNER(g:kikimr) - -PEERDIR( +LIBRARY() + +OWNER(g:kikimr) + +PEERDIR( ydb/core/filestore/core -) - -END() +) + +END() diff --git a/ydb/core/mind/hive/monitoring.cpp b/ydb/core/mind/hive/monitoring.cpp index b22eb884d0..7e9a83b354 100644 --- a/ydb/core/mind/hive/monitoring.cpp +++ b/ydb/core/mind/hive/monitoring.cpp @@ -1086,8 +1086,8 @@ public: return "K"; case TTabletTypes::SysViewProcessor: return "SV"; - case TTabletTypes::FileStore: - return "FS"; + case TTabletTypes::FileStore: + return "FS"; case TTabletTypes::TestShard: return "TS"; case TTabletTypes::SequenceShard: diff --git a/ydb/core/mon/mon.cpp b/ydb/core/mon/mon.cpp index 9bbe626f6b..d4722266f3 100644 --- a/ydb/core/mon/mon.cpp +++ b/ydb/core/mon/mon.cpp @@ -226,19 +226,19 @@ namespace NActors { //////////////////////////////////////////////////////////////////////////////// - // HTML results page - //////////////////////////////////////////////////////////////////////////////// - class THtmlResultMonPage: public THtmlMonPage { - public: + // HTML results page + //////////////////////////////////////////////////////////////////////////////// + class THtmlResultMonPage: public THtmlMonPage { + public: THtmlResultMonPage(const TString &path, const TString &title, const TString &host, bool preTag, - const NMon::IEvHttpInfoRes &result) - : THtmlMonPage(path, title, true) - , Host(host) - , PreTag(preTag) - , Result(result) - { - } - + const NMon::IEvHttpInfoRes &result) + : THtmlMonPage(path, title, true) + , Host(host) + , PreTag(preTag) + , Result(result) + { + } + void Output(NMonitoring::IMonHttpRequest& request) override { IOutputStream& out = request.Output(); @@ -287,23 +287,23 @@ namespace NActors { } void OutputContent(NMonitoring::IMonHttpRequest &request) override { - if (PreTag) { + if (PreTag) { request.Output() << "<pre>\n"; - } + } Result.Output(request.Output()); - if (PreTag) { + if (PreTag) { request.Output() << "</pre>\n"; - } - } - - private: + } + } + + private: TString Host; - bool PreTag; - const NMon::IEvHttpInfoRes &Result; - }; - - - //////////////////////////////////////////////////////////////////////////////// + bool PreTag; + const NMon::IEvHttpInfoRes &Result; + }; + + + //////////////////////////////////////////////////////////////////////////////// // INDEX PAGE // Redirects index page to fixed url //////////////////////////////////////////////////////////////////////////////// @@ -325,16 +325,16 @@ namespace NActors { //////////////////////////////////////////////////////////////////////////////// // ACTOR MONITORING PAGE - // Encapsulates a request to an actor + // Encapsulates a request to an actor //////////////////////////////////////////////////////////////////////////////// - class TActorMonPage: public IMonPage { + class TActorMonPage: public IMonPage { public: TActorMonPage(const TString &path, const TString &title, const TString &host, bool preTag, TActorSystem *actorSystem, const TActorId &actorId, const TVector<TString> &sids, TMon::TRequestAuthorizer authorizer) - : IMonPage(path, title) - , Host(host) - , PreTag(preTag) + : IMonPage(path, title) + , Host(host) + , PreTag(preTag) , ActorSystem(actorSystem) , TargetActorId(actorId) , AllowedSIDs(sids) @@ -353,27 +353,27 @@ namespace NActors { if (result) { Output(request, *result); } else { - TStringStream out; + TStringStream out; out << "Error: timeout. We were not able to receive response from '" - << Title << "'.\n"; - Output(request, NMon::TEvHttpInfoRes(out.Str())); + << Title << "'.\n"; + Output(request, NMon::TEvHttpInfoRes(out.Str())); } } private: void Output(IMonHttpRequest &request, const NMon::IEvHttpInfoRes &result) const { - if (result.GetContentType() == NMon::IEvHttpInfoRes::Html) { - THtmlResultMonPage resultPage(Path, Title, Host, PreTag, result); + if (result.GetContentType() == NMon::IEvHttpInfoRes::Html) { + THtmlResultMonPage resultPage(Path, Title, Host, PreTag, result); resultPage.Parent = this->Parent; - resultPage.Output(request); - } else { + resultPage.Output(request); + } else { result.Output(request.Output()); - } - } - - private: + } + } + + private: TString Host; - bool PreTag; + bool PreTag; TActorSystem *ActorSystem; TActorId TargetActorId; const TVector<TString> AllowedSIDs; diff --git a/ydb/core/mon_alloc/monitor.cpp b/ydb/core/mon_alloc/monitor.cpp index a21c918587..8afc7852c9 100644 --- a/ydb/core/mon_alloc/monitor.cpp +++ b/ydb/core/mon_alloc/monitor.cpp @@ -1,10 +1,10 @@ -#include "monitor.h" +#include "monitor.h" #include "tcmalloc.h" - + #include <ydb/core/base/counters.h> #include <ydb/core/base/appdata.h> #include <ydb/core/mon/mon.h> - + #include <library/cpp/actors/core/actor_bootstrapped.h> #include <library/cpp/actors/core/hfunc.h> #include <library/cpp/actors/prof/tag.h> @@ -14,37 +14,37 @@ #include <library/cpp/monlib/dynamic_counters/counters.h> #include <library/cpp/monlib/service/pages/templates.h> #include <library/cpp/ytalloc/api/ytalloc.h> - -#include <util/datetime/base.h> -#include <util/generic/hash.h> -#include <util/stream/str.h> - -namespace NKikimr { - using TDynamicCountersPtr = TIntrusivePtr<NMonitoring::TDynamicCounters>; - using TDynamicCounterPtr = NMonitoring::TDynamicCounters::TCounterPtr; - - namespace { - class TLfAllocMonitor: public IAllocMonitor { - struct TMemCounters { - TDynamicCounterPtr Count; - TDynamicCounterPtr Amount; - - void Init(TDynamicCountersPtr group) { - Count = group->GetCounter("count"); - Amount = group->GetCounter("amount"); - } - - void Set(ui64 count, ui64 amount) { - *Count = count; - *Amount = amount; - } - }; - - struct TPerTagCounters { - THashMap<TString, TMemCounters> BySize; - TMemCounters Total; - }; - + +#include <util/datetime/base.h> +#include <util/generic/hash.h> +#include <util/stream/str.h> + +namespace NKikimr { + using TDynamicCountersPtr = TIntrusivePtr<NMonitoring::TDynamicCounters>; + using TDynamicCounterPtr = NMonitoring::TDynamicCounters::TCounterPtr; + + namespace { + class TLfAllocMonitor: public IAllocMonitor { + struct TMemCounters { + TDynamicCounterPtr Count; + TDynamicCounterPtr Amount; + + void Init(TDynamicCountersPtr group) { + Count = group->GetCounter("count"); + Amount = group->GetCounter("amount"); + } + + void Set(ui64 count, ui64 amount) { + *Count = count; + *Amount = amount; + } + }; + + struct TPerTagCounters { + THashMap<TString, TMemCounters> BySize; + TMemCounters Total; + }; + struct TTagStats { struct TBucket { ui64 Count = 0; @@ -60,53 +60,53 @@ namespace NKikimr { TBucket Total; }; - private: - TDynamicCountersPtr CounterGroup; - - THashMap<TString, TPerTagCounters> PerTag; - TMemCounters Total; - - public: - TLfAllocMonitor(TDynamicCountersPtr group) { - CounterGroup = group->GetSubgroup("component", "lfalloc_profile"); - } - - void Update() override { + private: + TDynamicCountersPtr CounterGroup; + + THashMap<TString, TPerTagCounters> PerTag; + TMemCounters Total; + + public: + TLfAllocMonitor(TDynamicCountersPtr group) { + CounterGroup = group->GetSubgroup("component", "lfalloc_profile"); + } + + void Update() override { #ifdef PROFILE_MEMORY_ALLOCATIONS - int maxTag = 0; - int numSizes = 0; - auto info = NAllocDbg::GetPerTagAllocInfo(true, maxTag, numSizes); - + int maxTag = 0; + int numSizes = 0; + auto info = NAllocDbg::GetPerTagAllocInfo(true, maxTag, numSizes); + THashMap<TString, TTagStats> stats; - + auto& totalStats = stats["total"]; totalStats.Buckets.resize(numSizes); - // enumerate through all memory tags - for (int tag = 0; tag < maxTag; ++tag) { - auto tagName = NProfiling::GetTag(tag); - if (tagName == nullptr) { - tagName = "__DEFAULT__"; - } - + // enumerate through all memory tags + for (int tag = 0; tag < maxTag; ++tag) { + auto tagName = NProfiling::GetTag(tag); + if (tagName == nullptr) { + tagName = "__DEFAULT__"; + } + auto& tagStats = stats[tagName]; tagStats.Buckets.resize(numSizes); - - // enumerate through all sizes of objects - for (int sizeIdx = 0; sizeIdx < numSizes; ++sizeIdx) { - const auto& entry = info[tag * numSizes + sizeIdx]; - if (entry.Count <= 0) { - continue; - } - + + // enumerate through all sizes of objects + for (int sizeIdx = 0; sizeIdx < numSizes; ++sizeIdx) { + const auto& entry = info[tag * numSizes + sizeIdx]; + if (entry.Count <= 0) { + continue; + } + tagStats.Buckets[sizeIdx].Update(entry.Count, entry.Size); tagStats.Total.Update(entry.Count, entry.Size); - + totalStats.Buckets[sizeIdx].Update(entry.Count, entry.Size); totalStats.Total.Update(entry.Count, entry.Size); - } + } } - + // update counters for (const auto& [tagName, tagStats] : stats) { const auto& total = tagStats.Total; @@ -118,12 +118,12 @@ namespace NKikimr { } auto tagCounters = CounterGroup->GetSubgroup("tag", tagName); - if (!perTag.Total.Count) { - perTag.Total.Init(tagCounters->GetSubgroup("bucket", "total")); - } - + if (!perTag.Total.Count) { + perTag.Total.Init(tagCounters->GetSubgroup("bucket", "total")); + } + perTag.Total.Set(total.Count, total.Size); - + for (int sizeIdx = 0; sizeIdx < numSizes; ++sizeIdx) { const auto sizeName = ToString(sizeIdx); @@ -141,109 +141,109 @@ namespace NKikimr { bySize.Set(bucket.Count, bucket.Size); } - } + } #endif - } - + } + void Dump(IOutputStream& out, const TString& relPath) override { Y_UNUSED(relPath); #ifdef PROFILE_MEMORY_ALLOCATIONS - int maxTag = 0; - int numSizes = 0; - auto info = NAllocDbg::GetPerTagAllocInfo(true, maxTag, numSizes); - - HTML(out) { + int maxTag = 0; + int numSizes = 0; + auto info = NAllocDbg::GetPerTagAllocInfo(true, maxTag, numSizes); + + HTML(out) { H3() { out << "LFAlloc" << Endl; } out << "<hr>" << Endl; - TABLE_SORTABLE_CLASS("table") { - TABLEHEAD() { - TABLER() { - TABLEH() { - out << "<span data-toggle='tooltip' " - "title='Allocation Tag'>Tag</span>"; - } - TABLEH() { - out << "<span data-toggle='tooltip' " - "title='Size bucket'>Bucket</span>"; - } - TABLEH() { - out << "<span data-toggle='tooltip' " - "title='Count of allocated objects'>Count</span>"; - } - TABLEH() { - out << "<span data-toggle='tooltip' " - "title='Total amount of allocated RAM space'>" - "Total Space</span>"; - } - } - } - - TABLEBODY() { - // enumerate through all memory tags - for (int tag = 0; tag < maxTag; ++tag) { - auto tagName = NProfiling::GetTag(tag); - if (tagName == nullptr) { - tagName = "__DEFAULT__"; - } - - size_t totalAmountForTag = 0; - size_t totalCountForTag = 0; - ui32 tagRecordCount = 0; - - // enumerate through all sizes of objects - for (int sizeIdx = 0; sizeIdx < numSizes; ++sizeIdx) { - const auto& entry = info[tag * numSizes + sizeIdx]; - if (entry.Count <= 0) { - continue; - } - - totalCountForTag += entry.Count; - totalAmountForTag += entry.Size; - ++tagRecordCount; - - TABLER() { - TABLED() { - out << tagName; - } - TABLED() { - out << sizeIdx; - } - TABLED() { - out << entry.Count; - } - TABLED() { - out << entry.Size; - } - } - } - - if (totalCountForTag > 0 && tagRecordCount > 1) { - TABLER() { - TABLED() { - out << tagName; - } - TABLED() { - out << "overall"; - } - TABLED() { - out << totalCountForTag; - } - TABLED() { - out << totalAmountForTag; - } - } - } - } - } - } - - HTML_TAG() { - out << "<script>$(document).ready(function()" - "{$('[data-toggle=\"tooltip\"]').tooltip();}</script>"; - } - } + TABLE_SORTABLE_CLASS("table") { + TABLEHEAD() { + TABLER() { + TABLEH() { + out << "<span data-toggle='tooltip' " + "title='Allocation Tag'>Tag</span>"; + } + TABLEH() { + out << "<span data-toggle='tooltip' " + "title='Size bucket'>Bucket</span>"; + } + TABLEH() { + out << "<span data-toggle='tooltip' " + "title='Count of allocated objects'>Count</span>"; + } + TABLEH() { + out << "<span data-toggle='tooltip' " + "title='Total amount of allocated RAM space'>" + "Total Space</span>"; + } + } + } + + TABLEBODY() { + // enumerate through all memory tags + for (int tag = 0; tag < maxTag; ++tag) { + auto tagName = NProfiling::GetTag(tag); + if (tagName == nullptr) { + tagName = "__DEFAULT__"; + } + + size_t totalAmountForTag = 0; + size_t totalCountForTag = 0; + ui32 tagRecordCount = 0; + + // enumerate through all sizes of objects + for (int sizeIdx = 0; sizeIdx < numSizes; ++sizeIdx) { + const auto& entry = info[tag * numSizes + sizeIdx]; + if (entry.Count <= 0) { + continue; + } + + totalCountForTag += entry.Count; + totalAmountForTag += entry.Size; + ++tagRecordCount; + + TABLER() { + TABLED() { + out << tagName; + } + TABLED() { + out << sizeIdx; + } + TABLED() { + out << entry.Count; + } + TABLED() { + out << entry.Size; + } + } + } + + if (totalCountForTag > 0 && tagRecordCount > 1) { + TABLER() { + TABLED() { + out << tagName; + } + TABLED() { + out << "overall"; + } + TABLED() { + out << totalCountForTag; + } + TABLED() { + out << totalAmountForTag; + } + } + } + } + } + } + + HTML_TAG() { + out << "<script>$(document).ready(function()" + "{$('[data-toggle=\"tooltip\"]').tooltip();}</script>"; + } + } #else HTML(out) { H3() { @@ -253,107 +253,107 @@ namespace NKikimr { out << "PROFILE_MEMORY_ALLOCATIONS is off" << Endl; } #endif - } - }; - - class TYtAllocMonitor: public IAllocMonitor { - private: - TDynamicCountersPtr CounterGroup; - THashMap<TString, TDynamicCounterPtr> PerTag; - - public: - TYtAllocMonitor(TDynamicCountersPtr group) { - CounterGroup = group->GetSubgroup("component", "ytalloc_profile"); - } - - void Update() override { + } + }; + + class TYtAllocMonitor: public IAllocMonitor { + private: + TDynamicCountersPtr CounterGroup; + THashMap<TString, TDynamicCounterPtr> PerTag; + + public: + TYtAllocMonitor(TDynamicCountersPtr group) { + CounterGroup = group->GetSubgroup("component", "ytalloc_profile"); + } + + void Update() override { #ifdef PROFILE_MEMORY_ALLOCATIONS - using namespace NYT::NYTAlloc; - - size_t maxTag = NProfiling::GetTagsCount(); - - TVector<TMemoryTag> tags(maxTag); - std::iota(tags.begin(), tags.end(), 1); - - TVector<size_t> usages(maxTag); - GetMemoryUsageForTags(tags.data(), tags.size(), usages.data()); - - for (size_t tag = 0; tag < maxTag; ++tag) { - if (!usages[tag]) { - continue; - } - - auto tagName = NProfiling::GetTag(tag); - if (tagName == nullptr) { - tagName = "__DEFAULT__"; - } - - TDynamicCounterPtr& perTag = PerTag[tagName]; - if (!perTag) { - perTag = CounterGroup->GetCounter(tagName); - } - - *perTag = usages[tag]; - } + using namespace NYT::NYTAlloc; + + size_t maxTag = NProfiling::GetTagsCount(); + + TVector<TMemoryTag> tags(maxTag); + std::iota(tags.begin(), tags.end(), 1); + + TVector<size_t> usages(maxTag); + GetMemoryUsageForTags(tags.data(), tags.size(), usages.data()); + + for (size_t tag = 0; tag < maxTag; ++tag) { + if (!usages[tag]) { + continue; + } + + auto tagName = NProfiling::GetTag(tag); + if (tagName == nullptr) { + tagName = "__DEFAULT__"; + } + + TDynamicCounterPtr& perTag = PerTag[tagName]; + if (!perTag) { + perTag = CounterGroup->GetCounter(tagName); + } + + *perTag = usages[tag]; + } #endif - } - + } + void Dump(IOutputStream& out, const TString& relPath) override { Y_UNUSED(relPath); #ifdef PROFILE_MEMORY_ALLOCATIONS - using namespace NYT::NYTAlloc; - - size_t maxTag = NProfiling::GetTagsCount(); - - TVector<TMemoryTag> tags(maxTag); - std::iota(tags.begin(), tags.end(), 1); - - TVector<size_t> usages(maxTag); - GetMemoryUsageForTags(tags.data(), tags.size(), usages.data()); - - HTML(out) { + using namespace NYT::NYTAlloc; + + size_t maxTag = NProfiling::GetTagsCount(); + + TVector<TMemoryTag> tags(maxTag); + std::iota(tags.begin(), tags.end(), 1); + + TVector<size_t> usages(maxTag); + GetMemoryUsageForTags(tags.data(), tags.size(), usages.data()); + + HTML(out) { H3() { out << "YTAlloc" << Endl; } out << "<hr>" << Endl; - TABLE_SORTABLE_CLASS("table") { - TABLEHEAD() { - TABLER() { - TABLEH() { - out << "<span data-toggle='tooltip' " - "title='Allocation Tag'>Tag</span>"; - } - TABLEH() { - out << "<span data-toggle='tooltip' " - "title='Total amount of allocated RAM space'>" - "Total Space</span>"; - } - } - } - - TABLEBODY() { - for (size_t tag = 0; tag < maxTag; ++tag) { - if (!usages[tag]) { - continue; - } - - auto tagName = NProfiling::GetTag(tag); - if (tagName == nullptr) { - tagName = "__DEFAULT__"; - } - - TABLER() { - TABLED() { - out << tagName; - } - TABLED() { - out << usages[tag]; - } - } - } - } - } - } + TABLE_SORTABLE_CLASS("table") { + TABLEHEAD() { + TABLER() { + TABLEH() { + out << "<span data-toggle='tooltip' " + "title='Allocation Tag'>Tag</span>"; + } + TABLEH() { + out << "<span data-toggle='tooltip' " + "title='Total amount of allocated RAM space'>" + "Total Space</span>"; + } + } + } + + TABLEBODY() { + for (size_t tag = 0; tag < maxTag; ++tag) { + if (!usages[tag]) { + continue; + } + + auto tagName = NProfiling::GetTag(tag); + if (tagName == nullptr) { + tagName = "__DEFAULT__"; + } + + TABLER() { + TABLED() { + out << tagName; + } + TABLED() { + out << usages[tag]; + } + } + } + } + } + } #else HTML(out) { H3() { @@ -363,36 +363,36 @@ namespace NKikimr { out << "PROFILE_MEMORY_ALLOCATIONS is off" << Endl; } #endif - } - }; - - struct TFakeAllocMonitor: public IAllocMonitor { - void Update() override { - } - + } + }; + + struct TFakeAllocMonitor: public IAllocMonitor { + void Update() override { + } + void Dump(IOutputStream& out, const TString& relPath) override { - Y_UNUSED(out); + Y_UNUSED(out); Y_UNUSED(relPath); - } - }; - - std::unique_ptr<IAllocMonitor> CreateAllocMonitor(TDynamicCountersPtr group) { - const auto& info = NMalloc::MallocInfo(); + } + }; + + std::unique_ptr<IAllocMonitor> CreateAllocMonitor(TDynamicCountersPtr group) { + const auto& info = NMalloc::MallocInfo(); TStringBuf name(info.Name); - + std::unique_ptr<IAllocMonitor> monitor; - if (name.StartsWith("lf")) { + if (name.StartsWith("lf")) { monitor = std::make_unique<TLfAllocMonitor>(std::move(group)); - } else if (name.StartsWith("yt")) { + } else if (name.StartsWith("yt")) { monitor = std::make_unique<TYtAllocMonitor>(std::move(group)); } else if (name.StartsWith("tc")) { monitor = std::move(CreateTcMallocMonitor(std::move(group))); - } + } return monitor ? std::move(monitor) : std::make_unique<TFakeAllocMonitor>(); - } - - class TMemProfMonitor: public TActorBootstrapped<TMemProfMonitor> { + } + + class TMemProfMonitor: public TActorBootstrapped<TMemProfMonitor> { struct TDumpLogConfig { static constexpr double RssUsageHard = 0.9; static constexpr double RssUsageSoft = 0.85; @@ -407,53 +407,53 @@ namespace NKikimr { struct TEvDumpLogStats : public TEventLocal<TEvDumpLogStats, EvDumpLogStats> {}; - const TDuration Interval; - const std::unique_ptr<IAllocMonitor> AllocMonitor; - + const TDuration Interval; + const std::unique_ptr<IAllocMonitor> AllocMonitor; + TInstant LogMemoryStatsTime = TInstant::Now() - TDumpLogConfig::DumpInterval; bool IsDangerous = false; - public: - static constexpr EActivityType ActorActivityType() { - return ACTORLIB_STATS; - } - - TMemProfMonitor(TDuration interval, std::unique_ptr<IAllocMonitor> allocMonitor) - : Interval(interval) - , AllocMonitor(std::move(allocMonitor)) + public: + static constexpr EActivityType ActorActivityType() { + return ACTORLIB_STATS; + } + + TMemProfMonitor(TDuration interval, std::unique_ptr<IAllocMonitor> allocMonitor) + : Interval(interval) + , AllocMonitor(std::move(allocMonitor)) {} - - void Bootstrap(const TActorContext& ctx) { - NActors::TMon* mon = AppData(ctx)->Mon; - if (!mon) { - LOG_ERROR(ctx, NKikimrServices::MEMORY_PROFILER, - "Could not register actor page, 'mon' is null"); - Die(ctx); - return; - } - + + void Bootstrap(const TActorContext& ctx) { + NActors::TMon* mon = AppData(ctx)->Mon; + if (!mon) { + LOG_ERROR(ctx, NKikimrServices::MEMORY_PROFILER, + "Could not register actor page, 'mon' is null"); + Die(ctx); + return; + } + auto* indexPage = mon->RegisterIndexPage("memory", "Memory"); - mon->RegisterActorPage( + mon->RegisterActorPage( indexPage, "statistics", "Statistics", - false, ctx.ExecutorThread.ActorSystem, ctx.SelfID); - + false, ctx.ExecutorThread.ActorSystem, ctx.SelfID); + AllocMonitor->RegisterPages(mon, ctx.ExecutorThread.ActorSystem, ctx.SelfID); AllocMonitor->RegisterControls(AppData(ctx)->Icb); - Become(&TThis::StateWork); - ctx.Schedule(Interval, new TEvents::TEvWakeup()); - } - - private: - STFUNC(StateWork) { - switch (ev->GetTypeRewrite()) { - CFunc(TEvents::TEvWakeup::EventType, HandleWakeup); + Become(&TThis::StateWork); + ctx.Schedule(Interval, new TEvents::TEvWakeup()); + } + + private: + STFUNC(StateWork) { + switch (ev->GetTypeRewrite()) { + CFunc(TEvents::TEvWakeup::EventType, HandleWakeup); HFunc(TEvDumpLogStats, HandleDump); - HFunc(NMon::TEvHttpInfo, HandleHttpInfo); - } - } - + HFunc(NMon::TEvHttpInfo, HandleHttpInfo); + } + } + void LogMemoryStats(const TActorContext& ctx, size_t limit) noexcept { LogMemoryStatsTime = TInstant::Now(); TStringStream out; @@ -482,12 +482,12 @@ namespace NKikimr { } } - void HandleWakeup(const TActorContext& ctx) noexcept { - AllocMonitor->Update(); + void HandleWakeup(const TActorContext& ctx) noexcept { + AllocMonitor->Update(); LogMemoryStatsIfNeeded(ctx); - ctx.Schedule(Interval, new TEvents::TEvWakeup()); - } - + ctx.Schedule(Interval, new TEvents::TEvWakeup()); + } + void HandleDump(TEvDumpLogStats::TPtr&, const TActorContext& ctx) noexcept { if (IsDangerous) { auto memoryUsage = TAllocState::GetMemoryUsage(); @@ -497,10 +497,10 @@ namespace NKikimr { } } - void HandleHttpInfo(NMon::TEvHttpInfo::TPtr& ev, const TActorContext& ctx) noexcept { + void HandleHttpInfo(NMon::TEvHttpInfo::TPtr& ev, const TActorContext& ctx) noexcept { TString action = ev->Get()->Request.GetParams().Get("action"); TString relPath(ev->Get()->Request.GetPath()); - TStringStream out; + TStringStream out; if (action == "log" && relPath == "/memory/heap") { LogMemoryStats(ctx, 2048); out << "<p>Output dumped to log</p>" @@ -508,14 +508,14 @@ namespace NKikimr { } else { AllocMonitor->Dump(out, relPath); } - ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(out.Str())); - } - }; - } - - IActor* CreateMemProfMonitor(ui32 intervalSec, TDynamicCountersPtr counters) { - return new TMemProfMonitor( - TDuration::Seconds(intervalSec), - CreateAllocMonitor(GetServiceCounters(counters, "utils"))); - } -} + ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(out.Str())); + } + }; + } + + IActor* CreateMemProfMonitor(ui32 intervalSec, TDynamicCountersPtr counters) { + return new TMemProfMonitor( + TDuration::Seconds(intervalSec), + CreateAllocMonitor(GetServiceCounters(counters, "utils"))); + } +} diff --git a/ydb/core/mon_alloc/monitor.h b/ydb/core/mon_alloc/monitor.h index 91e166b964..f6a8404b65 100644 --- a/ydb/core/mon_alloc/monitor.h +++ b/ydb/core/mon_alloc/monitor.h @@ -4,7 +4,7 @@ #include <library/cpp/actors/core/defs.h> #include <library/cpp/actors/core/actor.h> - + #include <library/cpp/monlib/dynamic_counters/counters.h> namespace NActors { @@ -13,10 +13,10 @@ namespace NActors { namespace NKikimr { inline NActors::TActorId MakeMemProfMonitorID(ui32 node = 0) { - char x[12] = {'m', 'e', 'm', 'p', 'r', 'o', 'f', 'm', 'o', 'n', 'i', 't'}; + char x[12] = {'m', 'e', 'm', 'p', 'r', 'o', 'f', 'm', 'o', 'n', 'i', 't'}; return NActors::TActorId(node, TStringBuf(x, 12)); - } - + } + struct IAllocMonitor { virtual ~IAllocMonitor() = default; @@ -44,7 +44,7 @@ namespace NKikimr { } }; - NActors::IActor* CreateMemProfMonitor( - ui32 intervalSec, - TIntrusivePtr<NMonitoring::TDynamicCounters> counters); + NActors::IActor* CreateMemProfMonitor( + ui32 intervalSec, + TIntrusivePtr<NMonitoring::TDynamicCounters> counters); } diff --git a/ydb/core/mon_alloc/profiler.cpp b/ydb/core/mon_alloc/profiler.cpp index cebc35a9a6..bfff45c180 100644 --- a/ydb/core/mon_alloc/profiler.cpp +++ b/ydb/core/mon_alloc/profiler.cpp @@ -1,6 +1,6 @@ -#include "profiler.h" +#include "profiler.h" #include "tcmalloc.h" - + #include <library/cpp/actors/core/actorsystem.h> #include <library/cpp/actors/core/hfunc.h> #include <library/cpp/actors/core/mon.h> @@ -9,206 +9,206 @@ #include <library/cpp/html/pcdata/pcdata.h> #include <library/cpp/malloc/api/malloc.h> #include <library/cpp/monlib/service/pages/templates.h> - -#if defined(PROFILE_MEMORY_ALLOCATIONS) + +#if defined(PROFILE_MEMORY_ALLOCATIONS) #include <library/cpp/lfalloc/alloc_profiler/profiler.h> #include <library/cpp/ytalloc/api/ytalloc.h> -#endif - -#if defined(_linux_) && !defined(WITH_VALGRIND) -#define EXEC_PROFILER_ENABLED +#endif + +#if defined(_linux_) && !defined(WITH_VALGRIND) +#define EXEC_PROFILER_ENABLED #include <library/cpp/execprofile/profile.h> -#endif - -#include <util/datetime/base.h> -#include <util/stream/file.h> -#include <util/stream/str.h> -#include <util/string/printf.h> - -#include <stdio.h> - -namespace NActors { - using TDynamicCountersPtr = TIntrusivePtr<NMonitoring::TDynamicCounters>; - using TDynamicCounterPtr = NMonitoring::TDynamicCounters::TCounterPtr; - - namespace { - -#if defined(PROFILE_MEMORY_ALLOCATIONS) - struct TAllocDumper : NAllocProfiler::TAllocationStatsDumper { - using NAllocProfiler::TAllocationStatsDumper::TAllocationStatsDumper; - - TString FormatTag(int tag) override { - auto tagName = NProfiling::GetTag(tag); - return tagName ? tagName : "__DEFAULT__"; - } - }; - +#endif + +#include <util/datetime/base.h> +#include <util/stream/file.h> +#include <util/stream/str.h> +#include <util/string/printf.h> + +#include <stdio.h> + +namespace NActors { + using TDynamicCountersPtr = TIntrusivePtr<NMonitoring::TDynamicCounters>; + using TDynamicCounterPtr = NMonitoring::TDynamicCounters::TCounterPtr; + + namespace { + +#if defined(PROFILE_MEMORY_ALLOCATIONS) + struct TAllocDumper : NAllocProfiler::TAllocationStatsDumper { + using NAllocProfiler::TAllocationStatsDumper::TAllocationStatsDumper; + + TString FormatTag(int tag) override { + auto tagName = NProfiling::GetTag(tag); + return tagName ? tagName : "__DEFAULT__"; + } + }; + class TLfAllocProfiler: public IProfilerLogic { - public: - void Start() override { - NAllocProfiler::StartAllocationSampling(true); - } - + public: + void Start() override { + NAllocProfiler::StartAllocationSampling(true); + } + void Stop(IOutputStream& out, size_t limit, bool forLog) override { Y_UNUSED(forLog); - TAllocDumper dumper(out); - NAllocProfiler::StopAllocationSampling(dumper, limit); - } - }; - + TAllocDumper dumper(out); + NAllocProfiler::StopAllocationSampling(dumper, limit); + } + }; + class TYtAllocProfiler: public IProfilerLogic { - public: - TYtAllocProfiler() { - Init(); - } - - void Start() override { - SetEnabled(true); - } - + public: + TYtAllocProfiler() { + Init(); + } + + void Start() override { + SetEnabled(true); + } + void Stop(IOutputStream& out, size_t limit, bool forLog) override { Y_UNUSED(forLog); - DumpStats(out, limit); - SetEnabled(false); - } - - private: - static int BacktraceProvider(void** frames, int maxFrames, int skipFrames) { - int count = BackTrace(frames, maxFrames); - if (count > skipFrames) { - std::copy(&frames[skipFrames], &frames[count], frames); - count -= skipFrames; - } - return count; - } - - static void Init() { - using namespace NYT::NYTAlloc; - - SetBacktraceProvider(BacktraceProvider); - SetProfilingBacktraceDepth(MaxAllocationProfilingBacktraceDepth); - - // profile every allocation of any size - SetAllocationProfilingSamplingRate(1); - SetMinProfilingBytesUsedToReport(0); - } - - static void SetEnabled(bool enabled) { - using namespace NYT::NYTAlloc; - - SetAllocationProfilingEnabled(enabled); - - for (size_t rank = 0; rank < SmallRankCount; ++rank) { - SetSmallArenaAllocationProfilingEnabled(rank, enabled); - } - - for (size_t rank = 0; rank < LargeRankCount; ++rank) { - SetLargeArenaAllocationProfilingEnabled(rank, enabled); - } - } - - static void DumpStats(IOutputStream& out, size_t limit) { - using namespace NYT::NYTAlloc; - - struct TLess { - static auto AsTupleRef(const TProfiledAllocation& a) { - return std::forward_as_tuple( - a.Counters[EBasicCounter::BytesUsed], - a.Counters[EBasicCounter::BytesAllocated], - a.Counters[EBasicCounter::BytesFreed]); - } - - bool operator()(const TProfiledAllocation& l, const TProfiledAllocation& r) { - return AsTupleRef(r) < AsTupleRef(l); - } - }; - - auto allocations = GetProfiledAllocationStatistics(); - Sort(allocations, TLess()); - - NAllocProfiler::TStats total; - for (const auto& a : allocations) { - total.Alloc(a.Counters[EBasicCounter::BytesAllocated]); - total.Free(a.Counters[EBasicCounter::BytesFreed]); - } - - TAllocDumper dumper(out); - dumper.DumpTotal(total); - - size_t printedCount = 0; - for (const auto& a : allocations) { - NAllocProfiler::TAllocationInfo allocInfo; - allocInfo.Tag = 0; // not supported - allocInfo.Stats.Allocs = a.Counters[EBasicCounter::BytesAllocated]; - allocInfo.Stats.Frees = a.Counters[EBasicCounter::BytesFreed]; - allocInfo.Stats.CurrentSize = a.Counters[EBasicCounter::BytesUsed]; - - allocInfo.Stack.resize(a.Backtrace.FrameCount); - for (int i = 0; i < a.Backtrace.FrameCount; ++i) { - allocInfo.Stack[i] = a.Backtrace.Frames[i]; - } - - dumper.DumpEntry(allocInfo); - if (++printedCount >= limit) { - break; - } - } - } - }; -#endif // PROFILE_MEMORY_ALLOCATIONS - -#if defined(EXEC_PROFILER_ENABLED) + DumpStats(out, limit); + SetEnabled(false); + } + + private: + static int BacktraceProvider(void** frames, int maxFrames, int skipFrames) { + int count = BackTrace(frames, maxFrames); + if (count > skipFrames) { + std::copy(&frames[skipFrames], &frames[count], frames); + count -= skipFrames; + } + return count; + } + + static void Init() { + using namespace NYT::NYTAlloc; + + SetBacktraceProvider(BacktraceProvider); + SetProfilingBacktraceDepth(MaxAllocationProfilingBacktraceDepth); + + // profile every allocation of any size + SetAllocationProfilingSamplingRate(1); + SetMinProfilingBytesUsedToReport(0); + } + + static void SetEnabled(bool enabled) { + using namespace NYT::NYTAlloc; + + SetAllocationProfilingEnabled(enabled); + + for (size_t rank = 0; rank < SmallRankCount; ++rank) { + SetSmallArenaAllocationProfilingEnabled(rank, enabled); + } + + for (size_t rank = 0; rank < LargeRankCount; ++rank) { + SetLargeArenaAllocationProfilingEnabled(rank, enabled); + } + } + + static void DumpStats(IOutputStream& out, size_t limit) { + using namespace NYT::NYTAlloc; + + struct TLess { + static auto AsTupleRef(const TProfiledAllocation& a) { + return std::forward_as_tuple( + a.Counters[EBasicCounter::BytesUsed], + a.Counters[EBasicCounter::BytesAllocated], + a.Counters[EBasicCounter::BytesFreed]); + } + + bool operator()(const TProfiledAllocation& l, const TProfiledAllocation& r) { + return AsTupleRef(r) < AsTupleRef(l); + } + }; + + auto allocations = GetProfiledAllocationStatistics(); + Sort(allocations, TLess()); + + NAllocProfiler::TStats total; + for (const auto& a : allocations) { + total.Alloc(a.Counters[EBasicCounter::BytesAllocated]); + total.Free(a.Counters[EBasicCounter::BytesFreed]); + } + + TAllocDumper dumper(out); + dumper.DumpTotal(total); + + size_t printedCount = 0; + for (const auto& a : allocations) { + NAllocProfiler::TAllocationInfo allocInfo; + allocInfo.Tag = 0; // not supported + allocInfo.Stats.Allocs = a.Counters[EBasicCounter::BytesAllocated]; + allocInfo.Stats.Frees = a.Counters[EBasicCounter::BytesFreed]; + allocInfo.Stats.CurrentSize = a.Counters[EBasicCounter::BytesUsed]; + + allocInfo.Stack.resize(a.Backtrace.FrameCount); + for (int i = 0; i < a.Backtrace.FrameCount; ++i) { + allocInfo.Stack[i] = a.Backtrace.Frames[i]; + } + + dumper.DumpEntry(allocInfo); + if (++printedCount >= limit) { + break; + } + } + } + }; +#endif // PROFILE_MEMORY_ALLOCATIONS + +#if defined(EXEC_PROFILER_ENABLED) class TExecProfiler: public IProfilerLogic { - public: - void Start() override { - ResetProfile(); - BeginProfiling(); - } - + public: + void Start() override { + ResetProfile(); + BeginProfiling(); + } + void Stop(IOutputStream& out, size_t limit, bool forLog) override { - Y_UNUSED(limit); + Y_UNUSED(limit); Y_UNUSED(forLog); - - char* buf = nullptr; - size_t len = 0; - FILE* stream = open_memstream(&buf, &len); - Y_VERIFY(stream); - - EndProfiling(stream); - fflush(stream); - fclose(stream); - - out.Write(buf, len); - free(buf); - } - }; -#endif // EXEC_PROFILER_ENABLED - + + char* buf = nullptr; + size_t len = 0; + FILE* stream = open_memstream(&buf, &len); + Y_VERIFY(stream); + + EndProfiling(stream); + fflush(stream); + fclose(stream); + + out.Write(buf, len); + free(buf); + } + }; +#endif // EXEC_PROFILER_ENABLED + struct TFakeProfiler: public IProfilerLogic { - void Start() override { - } - + void Start() override { + } + void Stop(IOutputStream& out, size_t limit, bool forLog) override { - Y_UNUSED(out); - Y_UNUSED(limit); + Y_UNUSED(out); + Y_UNUSED(limit); Y_UNUSED(forLog); - } - }; - + } + }; + std::unique_ptr<IProfilerLogic> CreateProfiler() { - const auto& info = NMalloc::MallocInfo(); + const auto& info = NMalloc::MallocInfo(); TStringBuf name(info.Name); - + std::unique_ptr<IProfilerLogic> profiler; #if defined(PROFILE_MEMORY_ALLOCATIONS) - if (name.StartsWith("lf")) { + if (name.StartsWith("lf")) { profiler = std::make_unique<TLfAllocProfiler>(); - } else if (name.StartsWith("yt")) { + } else if (name.StartsWith("yt")) { profiler = std::make_unique<TYtAllocProfiler>(); - } -#endif // PROFILE_MEMORY_ALLOCATIONS - + } +#endif // PROFILE_MEMORY_ALLOCATIONS + if (name.StartsWith("tc")) { profiler = std::move(NKikimr::CreateTcMallocProfiler()); } @@ -217,153 +217,153 @@ namespace NActors { return std::move(profiler); } -#if defined(EXEC_PROFILER_ENABLED) - return std::make_unique<TExecProfiler>(); -#endif // EXEC_PROFILER_ENABLED - - return std::make_unique<TFakeProfiler>(); - } - - class TProfilerActor: public TActor<TProfilerActor> { - struct TCounters { - TDynamicCounterPtr IsProfiling; - }; - - private: - const TDynamicCountersPtr DynamicCounters; - const TString Dir; +#if defined(EXEC_PROFILER_ENABLED) + return std::make_unique<TExecProfiler>(); +#endif // EXEC_PROFILER_ENABLED + + return std::make_unique<TFakeProfiler>(); + } + + class TProfilerActor: public TActor<TProfilerActor> { + struct TCounters { + TDynamicCounterPtr IsProfiling; + }; + + private: + const TDynamicCountersPtr DynamicCounters; + const TString Dir; const std::unique_ptr<IProfilerLogic> Profiler; - - TCounters Counters; - bool IsProfiling = false; - ui32 Count = 0; - TInstant StartTime; - TInstant StopTime; - - public: - static constexpr EActivityType ActorActivityType() { - return ACTORLIB_STATS; - } - + + TCounters Counters; + bool IsProfiling = false; + ui32 Count = 0; + TInstant StartTime; + TInstant StopTime; + + public: + static constexpr EActivityType ActorActivityType() { + return ACTORLIB_STATS; + } + TProfilerActor(TDynamicCountersPtr counters, TString dir, std::unique_ptr<IProfilerLogic> profiler) - : TActor(&TThis::StateWork) - , DynamicCounters(std::move(counters)) - , Dir(std::move(dir)) - , Profiler(std::move(profiler)) - { - if (DynamicCounters) { - Counters.IsProfiling = DynamicCounters->GetCounter("IsProfiling"); - } - } - - private: - STFUNC(StateWork) { - switch (ev->GetTypeRewrite()) { - HFunc(TEvProfiler::TEvStart, HandleStart); - HFunc(TEvProfiler::TEvStop, HandleStop); - HFunc(NMon::TEvHttpInfo, HandleMonInfo); - } - } - + : TActor(&TThis::StateWork) + , DynamicCounters(std::move(counters)) + , Dir(std::move(dir)) + , Profiler(std::move(profiler)) + { + if (DynamicCounters) { + Counters.IsProfiling = DynamicCounters->GetCounter("IsProfiling"); + } + } + + private: + STFUNC(StateWork) { + switch (ev->GetTypeRewrite()) { + HFunc(TEvProfiler::TEvStart, HandleStart); + HFunc(TEvProfiler::TEvStop, HandleStop); + HFunc(NMon::TEvHttpInfo, HandleMonInfo); + } + } + void DumpProfilingTimes(IOutputStream& out); - void HandleStart(TEvProfiler::TEvStart::TPtr& ev, const TActorContext& ctx); - void HandleStop(TEvProfiler::TEvStop::TPtr& ev, const TActorContext& ctx); - void HandleMonInfo(NMon::TEvHttpInfo::TPtr& ev, const TActorContext& ctx); - - bool StartProfiler(); - bool StopProfiler(TString& profile); - bool StopProfilerFile(TString& outFileName, TString& err); + void HandleStart(TEvProfiler::TEvStart::TPtr& ev, const TActorContext& ctx); + void HandleStop(TEvProfiler::TEvStop::TPtr& ev, const TActorContext& ctx); + void HandleMonInfo(NMon::TEvHttpInfo::TPtr& ev, const TActorContext& ctx); + + bool StartProfiler(); + bool StopProfiler(TString& profile); + bool StopProfilerFile(TString& outFileName, TString& err); bool StopProfilerDumpToLog(const TActorContext& ctx); - - void OutputControlHtml(IOutputStream& os, const TString& action, bool isOk); - void OutputResultHtml(IOutputStream& os, const TString& action, const TString& profile, const TString& fileName, bool isOk, const TString& err); - }; - + + void OutputControlHtml(IOutputStream& os, const TString& action, bool isOk); + void OutputResultHtml(IOutputStream& os, const TString& action, const TString& profile, const TString& fileName, bool isOk, const TString& err); + }; + void TProfilerActor::DumpProfilingTimes(IOutputStream& out) { out << "Profiling started: " << StartTime << Endl << "Profiling stopped: " << StopTime << Endl << Endl; } - void TProfilerActor::HandleStart(TEvProfiler::TEvStart::TPtr& ev, const NActors::TActorContext& ctx) { - bool isOk = StartProfiler(); - ctx.Send(ev->Sender, new TEvProfiler::TEvStartResult(ev->Get()->Cookie(), isOk)); - } - - void TProfilerActor::HandleStop(TEvProfiler::TEvStop::TPtr& ev, const NActors::TActorContext& ctx) { - TString result; - bool isOk = StopProfiler(result); - ctx.Send(ev->Sender, new TEvProfiler::TEvStopResult(ev->Get()->Cookie(), result, isOk)); - } - - void TProfilerActor::HandleMonInfo(NMon::TEvHttpInfo::TPtr& ev, const TActorContext& ctx) { - TString action = ev->Get()->Request.GetParams().Get("action"); - TString profile; - TString fileName; - TString err; - - bool isOk = true; - if (action == "start") { - isOk = StartProfiler(); - } else if (action == "stop-display") { - isOk = StopProfiler(profile); - } else if (action == "stop-save") { - isOk = StopProfilerFile(fileName, err); + void TProfilerActor::HandleStart(TEvProfiler::TEvStart::TPtr& ev, const NActors::TActorContext& ctx) { + bool isOk = StartProfiler(); + ctx.Send(ev->Sender, new TEvProfiler::TEvStartResult(ev->Get()->Cookie(), isOk)); + } + + void TProfilerActor::HandleStop(TEvProfiler::TEvStop::TPtr& ev, const NActors::TActorContext& ctx) { + TString result; + bool isOk = StopProfiler(result); + ctx.Send(ev->Sender, new TEvProfiler::TEvStopResult(ev->Get()->Cookie(), result, isOk)); + } + + void TProfilerActor::HandleMonInfo(NMon::TEvHttpInfo::TPtr& ev, const TActorContext& ctx) { + TString action = ev->Get()->Request.GetParams().Get("action"); + TString profile; + TString fileName; + TString err; + + bool isOk = true; + if (action == "start") { + isOk = StartProfiler(); + } else if (action == "stop-display") { + isOk = StopProfiler(profile); + } else if (action == "stop-save") { + isOk = StopProfilerFile(fileName, err); } else if (action == "stop-log") { isOk = StopProfilerDumpToLog(ctx); - } - - TStringStream out; - HTML(out) { - DIV_CLASS("row") { - DIV_CLASS("col-md-12") { - OutputControlHtml(out, action, isOk); - } - } - DIV_CLASS("row") { - DIV_CLASS("col-md-12") { - OutputResultHtml(out, action, profile, fileName, isOk, err); - } - } - } - - ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(out.Str())); - } - - bool TProfilerActor::StartProfiler() { - if (IsProfiling) { - return false; - } - - IsProfiling = true; - StartTime = TInstant::Now(); - if (DynamicCounters) { - *Counters.IsProfiling = 1; - } - - Profiler->Start(); - return true; - } - - bool TProfilerActor::StopProfiler(TString& profile) { - if (!IsProfiling) { - profile.clear(); - return false; - } - - IsProfiling = false; - StopTime = TInstant::Now(); - if (DynamicCounters) { - *Counters.IsProfiling = 0; - } - - TStringOutput out(profile); + } + + TStringStream out; + HTML(out) { + DIV_CLASS("row") { + DIV_CLASS("col-md-12") { + OutputControlHtml(out, action, isOk); + } + } + DIV_CLASS("row") { + DIV_CLASS("col-md-12") { + OutputResultHtml(out, action, profile, fileName, isOk, err); + } + } + } + + ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(out.Str())); + } + + bool TProfilerActor::StartProfiler() { + if (IsProfiling) { + return false; + } + + IsProfiling = true; + StartTime = TInstant::Now(); + if (DynamicCounters) { + *Counters.IsProfiling = 1; + } + + Profiler->Start(); + return true; + } + + bool TProfilerActor::StopProfiler(TString& profile) { + if (!IsProfiling) { + profile.clear(); + return false; + } + + IsProfiling = false; + StopTime = TInstant::Now(); + if (DynamicCounters) { + *Counters.IsProfiling = 0; + } + + TStringOutput out(profile); DumpProfilingTimes(out); Profiler->Stop(out, 256, false); - return true; - } - + return true; + } + bool TProfilerActor::StopProfilerDumpToLog(const TActorContext& ctx) { if (!IsProfiling) { return false; @@ -387,89 +387,89 @@ namespace NActors { return true; } - bool TProfilerActor::StopProfilerFile(TString& outFileName, TString& err) { - if (!IsProfiling) { - outFileName.clear(); - return false; - } - - IsProfiling = false; - StopTime = TInstant::Now(); - if (DynamicCounters) { - *Counters.IsProfiling = 0; - } - - outFileName = Sprintf("%s/%s.%d.%u.profile", Dir.c_str(), getprogname(), (int)getpid(), ++Count); - Cerr << "Dumping profile to " << outFileName << Endl; - - try { - TFileOutput out(outFileName); + bool TProfilerActor::StopProfilerFile(TString& outFileName, TString& err) { + if (!IsProfiling) { + outFileName.clear(); + return false; + } + + IsProfiling = false; + StopTime = TInstant::Now(); + if (DynamicCounters) { + *Counters.IsProfiling = 0; + } + + outFileName = Sprintf("%s/%s.%d.%u.profile", Dir.c_str(), getprogname(), (int)getpid(), ++Count); + Cerr << "Dumping profile to " << outFileName << Endl; + + try { + TFileOutput out(outFileName); DumpProfilingTimes(out); Profiler->Stop(out, 4096, false); - } catch (const yexception& e) { - err = "Failed to dump profile: "; - err += e.what(); - Cerr << err << Endl; - return false; - } - - return true; - } - - void TProfilerActor::OutputControlHtml(IOutputStream& os, const TString& action, bool isOk) { - os << "<p>"; - if (IsProfiling) { - os << "<a class=\"btn btn-primary\" href=\"?action=stop-display\">Stop & display</a> \n"; + } catch (const yexception& e) { + err = "Failed to dump profile: "; + err += e.what(); + Cerr << err << Endl; + return false; + } + + return true; + } + + void TProfilerActor::OutputControlHtml(IOutputStream& os, const TString& action, bool isOk) { + os << "<p>"; + if (IsProfiling) { + os << "<a class=\"btn btn-primary\" href=\"?action=stop-display\">Stop & display</a> \n"; os << "<a class=\"btn btn-primary\" href=\"?action=stop-log\">Stop & dump to log</a>\n"; - os << "<a class=\"btn btn-primary\" href=\"?action=stop-save\">Stop & save to file</a>\n"; - } else { - os << "<a class=\"btn btn-primary\" href=\"?action=start\">Start</a>\n"; - if (action == "stop-display" && isOk) { - os << " <a class=\"btn btn-default\" onclick=\"" - << "javascript:$('.container').removeClass('container').addClass('container-fluid');$(this).hide();" - << "\">Full width</a>"; - } - } - os << "</p>"; - } - - void TProfilerActor::OutputResultHtml(IOutputStream& os, const TString& action, const TString& profile, const TString& fileName, bool isOk, const TString& err) { - if (action == "stop-display") { - if (isOk) { - os << "<div style=\"overflow-y: scroll;\"><pre " - << "style=\"overflow: auto;word-wrap: normal;white-space: pre;\">" - << EncodeHtmlPcdata(profile) << "</pre></div>\n"; - } else { - os << "<p>Error stopping profiling.</p>"; - } - } else if (action == "stop-save") { - if (isOk) { - os << "<p>Output saved to: " << fileName << "</p>"; - } else { - os << "<p>Error stopping profiling, "; - os << "filename: " << fileName; - os << "</p><p>Error: " << err << "</p>"; - } + os << "<a class=\"btn btn-primary\" href=\"?action=stop-save\">Stop & save to file</a>\n"; + } else { + os << "<a class=\"btn btn-primary\" href=\"?action=start\">Start</a>\n"; + if (action == "stop-display" && isOk) { + os << " <a class=\"btn btn-default\" onclick=\"" + << "javascript:$('.container').removeClass('container').addClass('container-fluid');$(this).hide();" + << "\">Full width</a>"; + } + } + os << "</p>"; + } + + void TProfilerActor::OutputResultHtml(IOutputStream& os, const TString& action, const TString& profile, const TString& fileName, bool isOk, const TString& err) { + if (action == "stop-display") { + if (isOk) { + os << "<div style=\"overflow-y: scroll;\"><pre " + << "style=\"overflow: auto;word-wrap: normal;white-space: pre;\">" + << EncodeHtmlPcdata(profile) << "</pre></div>\n"; + } else { + os << "<p>Error stopping profiling.</p>"; + } + } else if (action == "stop-save") { + if (isOk) { + os << "<p>Output saved to: " << fileName << "</p>"; + } else { + os << "<p>Error stopping profiling, "; + os << "filename: " << fileName; + os << "</p><p>Error: " << err << "</p>"; + } } else if (action == "stop-log") { if (isOk) { os << "<p>Output dumped to log</p>"; } else { os << "<p>Error stopping profiling.</p>"; } - } else if (action == "start") { - if (isOk) { - os << "<p>Profiling started OK.</p>"; - } else { - os << "<p>Error starting profiling.</p>"; - } - } - } - } - + } else if (action == "start") { + if (isOk) { + os << "<p>Profiling started OK.</p>"; + } else { + os << "<p>Error starting profiling.</p>"; + } + } + } + } + IActor* CreateProfilerActor(TDynamicCountersPtr counters, TString dir, std::unique_ptr<IProfilerLogic> profiler) { - return new TProfilerActor( - std::move(counters), - std::move(dir), + return new TProfilerActor( + std::move(counters), + std::move(dir), profiler ? std::move(profiler) : CreateProfiler()); - } -} + } +} diff --git a/ydb/core/mon_alloc/profiler.h b/ydb/core/mon_alloc/profiler.h index 0941147168..4fba8941da 100644 --- a/ydb/core/mon_alloc/profiler.h +++ b/ydb/core/mon_alloc/profiler.h @@ -1,109 +1,109 @@ -#pragma once - +#pragma once + #include <ydb/core/protos/profiler.pb.h> - + #include <library/cpp/actors/core/actor.h> #include <library/cpp/actors/core/defs.h> #include <library/cpp/actors/core/event_pb.h> #include <library/cpp/actors/core/events.h> - + #include <library/cpp/monlib/dynamic_counters/counters.h> - -#include <util/generic/string.h> - -namespace NActors { - struct TEvProfiler { - enum EEv { - EvStart = EventSpaceBegin(TEvents::ES_PROFILER), - EvStop, - EvStartResult, - EvStopResult, - EvEnd - }; - - enum ESubscribes { - SubConnected, - SubDisconnected, - }; - - static_assert(EvEnd < EventSpaceEnd(TEvents::ES_PROFILER), "ES_PROFILER event space is too small."); - - class TEvStart: public TEventPB<TEvStart, NActorsProfiler::TEvStart, EvStart> { - public: - TEvStart() { - } - - TEvStart(ui64 cookie) { - if (cookie) { - Record.SetCookie(cookie); - } - } - - ui64 Cookie() { - return Record.HasCookie() ? Record.GetCookie() : 0; - } - }; - - class TEvStartResult: public TEventPB<TEvStartResult, NActorsProfiler::TEvStartResult, EvStartResult> { - public: - TEvStartResult() { - } - - TEvStartResult(ui64 cookie, bool isOk) { - Record.SetCookie(cookie); - Record.SetIsOk(isOk); - } - - ui64 Cookie() { - return Record.HasCookie() ? Record.GetCookie() : 0; - } - - bool IsOk() { - return Record.HasIsOk() ? Record.GetIsOk() : false; - } - }; - - class TEvStop: public TEventPB<TEvStop, NActorsProfiler::TEvStop, EvStop> { - public: - TEvStop() { - } - - TEvStop(ui64 cookie) { - if (cookie) { - Record.SetCookie(cookie); - } - } - - ui64 Cookie() { - return Record.HasCookie() ? Record.GetCookie() : 0; - } - }; - - class TEvStopResult: public TEventPB<TEvStopResult, NActorsProfiler::TEvStopResult, EvStopResult> { - public: - TEvStopResult() { - } - - TEvStopResult(ui64 cookie, TString profile, bool isOk) { - Record.SetCookie(cookie); - Record.SetProfile(profile); - Record.SetIsOk(isOk); - } - - ui64 Cookie() { - return Record.HasCookie() ? Record.GetCookie() : 0; - } - - TString Profile() { - return Record.HasProfile() ? Record.GetProfile() : TString(); - } - - bool IsOk() { - return Record.HasIsOk() ? Record.GetIsOk() : false; - } - }; - }; - + +#include <util/generic/string.h> + +namespace NActors { + struct TEvProfiler { + enum EEv { + EvStart = EventSpaceBegin(TEvents::ES_PROFILER), + EvStop, + EvStartResult, + EvStopResult, + EvEnd + }; + + enum ESubscribes { + SubConnected, + SubDisconnected, + }; + + static_assert(EvEnd < EventSpaceEnd(TEvents::ES_PROFILER), "ES_PROFILER event space is too small."); + + class TEvStart: public TEventPB<TEvStart, NActorsProfiler::TEvStart, EvStart> { + public: + TEvStart() { + } + + TEvStart(ui64 cookie) { + if (cookie) { + Record.SetCookie(cookie); + } + } + + ui64 Cookie() { + return Record.HasCookie() ? Record.GetCookie() : 0; + } + }; + + class TEvStartResult: public TEventPB<TEvStartResult, NActorsProfiler::TEvStartResult, EvStartResult> { + public: + TEvStartResult() { + } + + TEvStartResult(ui64 cookie, bool isOk) { + Record.SetCookie(cookie); + Record.SetIsOk(isOk); + } + + ui64 Cookie() { + return Record.HasCookie() ? Record.GetCookie() : 0; + } + + bool IsOk() { + return Record.HasIsOk() ? Record.GetIsOk() : false; + } + }; + + class TEvStop: public TEventPB<TEvStop, NActorsProfiler::TEvStop, EvStop> { + public: + TEvStop() { + } + + TEvStop(ui64 cookie) { + if (cookie) { + Record.SetCookie(cookie); + } + } + + ui64 Cookie() { + return Record.HasCookie() ? Record.GetCookie() : 0; + } + }; + + class TEvStopResult: public TEventPB<TEvStopResult, NActorsProfiler::TEvStopResult, EvStopResult> { + public: + TEvStopResult() { + } + + TEvStopResult(ui64 cookie, TString profile, bool isOk) { + Record.SetCookie(cookie); + Record.SetProfile(profile); + Record.SetIsOk(isOk); + } + + ui64 Cookie() { + return Record.HasCookie() ? Record.GetCookie() : 0; + } + + TString Profile() { + return Record.HasProfile() ? Record.GetProfile() : TString(); + } + + bool IsOk() { + return Record.HasIsOk() ? Record.GetIsOk() : false; + } + }; + }; + struct IProfilerLogic { virtual ~IProfilerLogic() = default; virtual void Start() = 0; @@ -111,12 +111,12 @@ namespace NActors { }; inline TActorId MakeProfilerID(ui32 nodeId) { - char x[12] = {'p', 'r', 'o', 'f', 'i', 'l', 'e', 'r', 's', 'e', 'r', 'v'}; + char x[12] = {'p', 'r', 'o', 'f', 'i', 'l', 'e', 'r', 's', 'e', 'r', 'v'}; return TActorId(nodeId, TStringBuf(x, 12)); - } - - IActor* CreateProfilerActor( - TIntrusivePtr<NMonitoring::TDynamicCounters> counters, + } + + IActor* CreateProfilerActor( + TIntrusivePtr<NMonitoring::TDynamicCounters> counters, TString dir, std::unique_ptr<IProfilerLogic> profiler = nullptr); -} +} diff --git a/ydb/core/mon_alloc/stats.cpp b/ydb/core/mon_alloc/stats.cpp index 10fda18c33..050822241c 100644 --- a/ydb/core/mon_alloc/stats.cpp +++ b/ydb/core/mon_alloc/stats.cpp @@ -1,8 +1,8 @@ -#include "stats.h" +#include "stats.h" #include "tcmalloc.h" - + #include <ydb/core/base/counters.h> - + #include <library/cpp/actors/core/actor_bootstrapped.h> #include <library/cpp/actors/core/hfunc.h> #include <library/cpp/actors/core/process_stats.h> @@ -10,246 +10,246 @@ #include <library/cpp/malloc/api/malloc.h> #include <library/cpp/monlib/dynamic_counters/counters.h> #include <library/cpp/ytalloc/api/ytalloc.h> - -#include <util/datetime/base.h> - -namespace NKikimr { - using TDynamicCountersPtr = TIntrusivePtr<NMonitoring::TDynamicCounters>; - using TDynamicCounterPtr = NMonitoring::TDynamicCounters::TCounterPtr; - - namespace { - class TLfAllocStats: public IAllocStats { - private: - TDynamicCountersPtr CounterGroup; - - TDynamicCounterPtr MmapCount; - TDynamicCounterPtr MunmapCount; - TDynamicCounterPtr SlowAllocCount; - TDynamicCounterPtr DefragmentMemCount; - - TDynamicCounterPtr BytesSmall; - TDynamicCounterPtr BytesLarge; - TDynamicCounterPtr BytesSystem; - TDynamicCounterPtr BytesMmapped; - - TDynamicCounterPtr ActiveBytesSmall; - TDynamicCounterPtr ActiveBytesLarge; - TDynamicCounterPtr ActiveBytesSystem; - TDynamicCounterPtr ActiveBytesMmapped; - - public: - TLfAllocStats(TDynamicCountersPtr group) { - CounterGroup = group->GetSubgroup("component", "lfalloc"); - - MmapCount = CounterGroup->GetCounter("MmapCount", true); - MunmapCount = CounterGroup->GetCounter("MunmapCount", true); - SlowAllocCount = CounterGroup->GetCounter("SlowAllocCount", true); - DefragmentMemCount = CounterGroup->GetCounter("DefragmentMemCount", true); - - BytesSmall = CounterGroup->GetCounter("BytesSmall", true); - BytesLarge = CounterGroup->GetCounter("BytesLarge", true); - BytesSystem = CounterGroup->GetCounter("BytesSystem", true); - BytesMmapped = CounterGroup->GetCounter("BytesMmapped", true); - - ActiveBytesSmall = CounterGroup->GetCounter("ActiveBytesSmall"); - ActiveBytesLarge = CounterGroup->GetCounter("ActiveBytesLarge"); - ActiveBytesSystem = CounterGroup->GetCounter("ActiveBytesSystem"); - ActiveBytesMmapped = CounterGroup->GetCounter("ActiveBytesMmapped"); - } - - void Update() override { - using namespace NAllocDbg; - - *MmapCount = GetAllocationCounterFast(CT_MMAP_CNT); - *MunmapCount = GetAllocationCounterFast(CT_MUNMAP_CNT); - *SlowAllocCount = GetAllocationCounterFast(CT_SLOW_ALLOC_CNT); - *DefragmentMemCount = GetAllocationCounterFast(CT_DEGRAGMENT_CNT); - - i64 systemAllocated = GetAllocationCounterFast(CT_SYSTEM_ALLOC); - i64 systemFreed = GetAllocationCounterFast(CT_SYSTEM_FREE); - i64 smallAllocated = GetAllocationCounterFast(CT_SMALL_ALLOC); - i64 smallFreed = GetAllocationCounterFast(CT_SMALL_FREE); - i64 largeAllocated = GetAllocationCounterFast(CT_LARGE_ALLOC); - i64 largeFreed = GetAllocationCounterFast(CT_LARGE_FREE); - i64 totalMmaped = GetAllocationCounterFast(CT_MMAP); - i64 totalMunmaped = GetAllocationCounterFast(CT_MUNMAP); - - *BytesSystem = systemAllocated; - *BytesSmall = smallAllocated; - *BytesLarge = largeAllocated; - *BytesMmapped = totalMmaped; - - systemAllocated -= systemFreed; - smallAllocated -= smallFreed; - largeAllocated -= largeFreed; - totalMmaped -= totalMunmaped; - - *ActiveBytesSystem = systemAllocated > 0 ? systemAllocated : 0; - *ActiveBytesSmall = smallAllocated > 0 ? smallAllocated : 0; - *ActiveBytesLarge = largeAllocated > 0 ? largeAllocated : 0; - *ActiveBytesMmapped = totalMmaped > 0 ? totalMmaped : 0; - } - }; - - class TYtAllocStats: public IAllocStats { - struct TTimingEventCounters { - TDynamicCounterPtr Count; - TDynamicCounterPtr Size; - }; - - private: - TDynamicCountersPtr CounterGroup; - - NYT::TEnumIndexedVector<NYT::NYTAlloc::ETotalCounter, TDynamicCounterPtr> TotalAllocationCounters; - NYT::TEnumIndexedVector<NYT::NYTAlloc::ESmallCounter, TDynamicCounterPtr> SmallAllocationCounters; - NYT::TEnumIndexedVector<NYT::NYTAlloc::ELargeCounter, TDynamicCounterPtr> LargeAllocationCounters; - std::array<NYT::TEnumIndexedVector<NYT::NYTAlloc::ESmallArenaCounter, TDynamicCounterPtr>, NYT::NYTAlloc::SmallRankCount> SmallArenaAllocationCounters; - std::array<NYT::TEnumIndexedVector<NYT::NYTAlloc::ELargeArenaCounter, TDynamicCounterPtr>, NYT::NYTAlloc::LargeRankCount> LargeArenaAllocationCounters; - NYT::TEnumIndexedVector<NYT::NYTAlloc::EHugeCounter, TDynamicCounterPtr> HugeAllocationCounters; - NYT::TEnumIndexedVector<NYT::NYTAlloc::ESystemCounter, TDynamicCounterPtr> SystemAllocationCounters; - NYT::TEnumIndexedVector<NYT::NYTAlloc::EUndumpableCounter, TDynamicCounterPtr> UndumpableAllocationCounters; - NYT::TEnumIndexedVector<NYT::NYTAlloc::ETimingEventType, TTimingEventCounters> TimingEventCounters; - - public: - TYtAllocStats(TDynamicCountersPtr group) { - CounterGroup = group->GetSubgroup("component", "ytalloc"); - - InitCounters(TotalAllocationCounters, CounterGroup->GetSubgroup("category", "total")); - InitCounters(SmallAllocationCounters, CounterGroup->GetSubgroup("category", "small")); - InitCounters(LargeAllocationCounters, CounterGroup->GetSubgroup("category", "large")); - InitCounters(SmallArenaAllocationCounters, CounterGroup->GetSubgroup("category", "small_arena")); - InitCounters(LargeArenaAllocationCounters, CounterGroup->GetSubgroup("category", "large_arena")); - InitCounters(HugeAllocationCounters, CounterGroup->GetSubgroup("category", "huge")); - InitCounters(SystemAllocationCounters, CounterGroup->GetSubgroup("category", "system")); - InitCounters(UndumpableAllocationCounters, CounterGroup->GetSubgroup("category", "undumpable")); - InitCounters(TimingEventCounters, CounterGroup->GetSubgroup("category", "timing_event")); - } - - void Update() override { - UpdateCounters(TotalAllocationCounters, NYT::NYTAlloc::GetTotalAllocationCounters()); - UpdateCounters(SmallAllocationCounters, NYT::NYTAlloc::GetSmallAllocationCounters()); - UpdateCounters(LargeAllocationCounters, NYT::NYTAlloc::GetLargeAllocationCounters()); - UpdateCounters(SmallArenaAllocationCounters, NYT::NYTAlloc::GetSmallArenaAllocationCounters()); - UpdateCounters(LargeArenaAllocationCounters, NYT::NYTAlloc::GetLargeArenaAllocationCounters()); - UpdateCounters(HugeAllocationCounters, NYT::NYTAlloc::GetHugeAllocationCounters()); - UpdateCounters(SystemAllocationCounters, NYT::NYTAlloc::GetSystemAllocationCounters()); - UpdateCounters(UndumpableAllocationCounters, NYT::NYTAlloc::GetUndumpableAllocationCounters()); - UpdateCounters(TimingEventCounters, NYT::NYTAlloc::GetTimingEventCounters()); - } - - private: - template <typename E> - static void InitCounters( - NYT::TEnumIndexedVector<E, TDynamicCounterPtr>& counters, - TDynamicCountersPtr group) { - for (auto c : NYT::TEnumTraits<E>::GetDomainValues()) { - counters[c] = group->GetCounter(NYT::TEnumTraits<E>::ToString(c)); - } - } - - template <typename E, size_t N> - static void InitCounters( - std::array<NYT::TEnumIndexedVector<E, TDynamicCounterPtr>, N>& counters, - TDynamicCountersPtr group) { - for (size_t i = 0; i < N; ++i) { - InitCounters(counters[i], group->GetSubgroup("rank", ToString(i))); - } - } - - template <typename E> - static void InitCounters( - NYT::TEnumIndexedVector<E, TTimingEventCounters>& counters, - TDynamicCountersPtr group) { - for (auto c : NYT::TEnumTraits<E>::GetDomainValues()) { - const auto& name = NYT::TEnumTraits<E>::ToString(c); - counters[c].Count = group->GetCounter(name + "_Count"); - counters[c].Size = group->GetCounter(name + "_Size"); - } - } - - template <typename E> - static void UpdateCounters( - NYT::TEnumIndexedVector<E, TDynamicCounterPtr>& counters, - const NYT::TEnumIndexedVector<E, ssize_t>& source) { - for (auto c : NYT::TEnumTraits<E>::GetDomainValues()) { - *counters[c] = source[c]; - } - } - - template <typename E, size_t N> - static void UpdateCounters( - std::array<NYT::TEnumIndexedVector<E, TDynamicCounterPtr>, N>& counters, - const std::array<NYT::TEnumIndexedVector<E, ssize_t>, N>& source) { - for (size_t i = 0; i < N; ++i) { - UpdateCounters(counters[i], source[i]); - } - } - - template <typename E> - static void UpdateCounters( - NYT::TEnumIndexedVector<E, TTimingEventCounters>& counters, - const NYT::TEnumIndexedVector<E, NYT::NYTAlloc::TTimingEventCounters>& source) { - for (auto c : NYT::TEnumTraits<E>::GetDomainValues()) { - *counters[c].Count = source[c].Count; - *counters[c].Size = source[c].Size; - } - } - }; - - struct TFakeAllocStats: public IAllocStats { - void Update() override { - } - }; - - std::unique_ptr<IAllocStats> CreateAllocStats(TDynamicCountersPtr group) { - const auto& info = NMalloc::MallocInfo(); + +#include <util/datetime/base.h> + +namespace NKikimr { + using TDynamicCountersPtr = TIntrusivePtr<NMonitoring::TDynamicCounters>; + using TDynamicCounterPtr = NMonitoring::TDynamicCounters::TCounterPtr; + + namespace { + class TLfAllocStats: public IAllocStats { + private: + TDynamicCountersPtr CounterGroup; + + TDynamicCounterPtr MmapCount; + TDynamicCounterPtr MunmapCount; + TDynamicCounterPtr SlowAllocCount; + TDynamicCounterPtr DefragmentMemCount; + + TDynamicCounterPtr BytesSmall; + TDynamicCounterPtr BytesLarge; + TDynamicCounterPtr BytesSystem; + TDynamicCounterPtr BytesMmapped; + + TDynamicCounterPtr ActiveBytesSmall; + TDynamicCounterPtr ActiveBytesLarge; + TDynamicCounterPtr ActiveBytesSystem; + TDynamicCounterPtr ActiveBytesMmapped; + + public: + TLfAllocStats(TDynamicCountersPtr group) { + CounterGroup = group->GetSubgroup("component", "lfalloc"); + + MmapCount = CounterGroup->GetCounter("MmapCount", true); + MunmapCount = CounterGroup->GetCounter("MunmapCount", true); + SlowAllocCount = CounterGroup->GetCounter("SlowAllocCount", true); + DefragmentMemCount = CounterGroup->GetCounter("DefragmentMemCount", true); + + BytesSmall = CounterGroup->GetCounter("BytesSmall", true); + BytesLarge = CounterGroup->GetCounter("BytesLarge", true); + BytesSystem = CounterGroup->GetCounter("BytesSystem", true); + BytesMmapped = CounterGroup->GetCounter("BytesMmapped", true); + + ActiveBytesSmall = CounterGroup->GetCounter("ActiveBytesSmall"); + ActiveBytesLarge = CounterGroup->GetCounter("ActiveBytesLarge"); + ActiveBytesSystem = CounterGroup->GetCounter("ActiveBytesSystem"); + ActiveBytesMmapped = CounterGroup->GetCounter("ActiveBytesMmapped"); + } + + void Update() override { + using namespace NAllocDbg; + + *MmapCount = GetAllocationCounterFast(CT_MMAP_CNT); + *MunmapCount = GetAllocationCounterFast(CT_MUNMAP_CNT); + *SlowAllocCount = GetAllocationCounterFast(CT_SLOW_ALLOC_CNT); + *DefragmentMemCount = GetAllocationCounterFast(CT_DEGRAGMENT_CNT); + + i64 systemAllocated = GetAllocationCounterFast(CT_SYSTEM_ALLOC); + i64 systemFreed = GetAllocationCounterFast(CT_SYSTEM_FREE); + i64 smallAllocated = GetAllocationCounterFast(CT_SMALL_ALLOC); + i64 smallFreed = GetAllocationCounterFast(CT_SMALL_FREE); + i64 largeAllocated = GetAllocationCounterFast(CT_LARGE_ALLOC); + i64 largeFreed = GetAllocationCounterFast(CT_LARGE_FREE); + i64 totalMmaped = GetAllocationCounterFast(CT_MMAP); + i64 totalMunmaped = GetAllocationCounterFast(CT_MUNMAP); + + *BytesSystem = systemAllocated; + *BytesSmall = smallAllocated; + *BytesLarge = largeAllocated; + *BytesMmapped = totalMmaped; + + systemAllocated -= systemFreed; + smallAllocated -= smallFreed; + largeAllocated -= largeFreed; + totalMmaped -= totalMunmaped; + + *ActiveBytesSystem = systemAllocated > 0 ? systemAllocated : 0; + *ActiveBytesSmall = smallAllocated > 0 ? smallAllocated : 0; + *ActiveBytesLarge = largeAllocated > 0 ? largeAllocated : 0; + *ActiveBytesMmapped = totalMmaped > 0 ? totalMmaped : 0; + } + }; + + class TYtAllocStats: public IAllocStats { + struct TTimingEventCounters { + TDynamicCounterPtr Count; + TDynamicCounterPtr Size; + }; + + private: + TDynamicCountersPtr CounterGroup; + + NYT::TEnumIndexedVector<NYT::NYTAlloc::ETotalCounter, TDynamicCounterPtr> TotalAllocationCounters; + NYT::TEnumIndexedVector<NYT::NYTAlloc::ESmallCounter, TDynamicCounterPtr> SmallAllocationCounters; + NYT::TEnumIndexedVector<NYT::NYTAlloc::ELargeCounter, TDynamicCounterPtr> LargeAllocationCounters; + std::array<NYT::TEnumIndexedVector<NYT::NYTAlloc::ESmallArenaCounter, TDynamicCounterPtr>, NYT::NYTAlloc::SmallRankCount> SmallArenaAllocationCounters; + std::array<NYT::TEnumIndexedVector<NYT::NYTAlloc::ELargeArenaCounter, TDynamicCounterPtr>, NYT::NYTAlloc::LargeRankCount> LargeArenaAllocationCounters; + NYT::TEnumIndexedVector<NYT::NYTAlloc::EHugeCounter, TDynamicCounterPtr> HugeAllocationCounters; + NYT::TEnumIndexedVector<NYT::NYTAlloc::ESystemCounter, TDynamicCounterPtr> SystemAllocationCounters; + NYT::TEnumIndexedVector<NYT::NYTAlloc::EUndumpableCounter, TDynamicCounterPtr> UndumpableAllocationCounters; + NYT::TEnumIndexedVector<NYT::NYTAlloc::ETimingEventType, TTimingEventCounters> TimingEventCounters; + + public: + TYtAllocStats(TDynamicCountersPtr group) { + CounterGroup = group->GetSubgroup("component", "ytalloc"); + + InitCounters(TotalAllocationCounters, CounterGroup->GetSubgroup("category", "total")); + InitCounters(SmallAllocationCounters, CounterGroup->GetSubgroup("category", "small")); + InitCounters(LargeAllocationCounters, CounterGroup->GetSubgroup("category", "large")); + InitCounters(SmallArenaAllocationCounters, CounterGroup->GetSubgroup("category", "small_arena")); + InitCounters(LargeArenaAllocationCounters, CounterGroup->GetSubgroup("category", "large_arena")); + InitCounters(HugeAllocationCounters, CounterGroup->GetSubgroup("category", "huge")); + InitCounters(SystemAllocationCounters, CounterGroup->GetSubgroup("category", "system")); + InitCounters(UndumpableAllocationCounters, CounterGroup->GetSubgroup("category", "undumpable")); + InitCounters(TimingEventCounters, CounterGroup->GetSubgroup("category", "timing_event")); + } + + void Update() override { + UpdateCounters(TotalAllocationCounters, NYT::NYTAlloc::GetTotalAllocationCounters()); + UpdateCounters(SmallAllocationCounters, NYT::NYTAlloc::GetSmallAllocationCounters()); + UpdateCounters(LargeAllocationCounters, NYT::NYTAlloc::GetLargeAllocationCounters()); + UpdateCounters(SmallArenaAllocationCounters, NYT::NYTAlloc::GetSmallArenaAllocationCounters()); + UpdateCounters(LargeArenaAllocationCounters, NYT::NYTAlloc::GetLargeArenaAllocationCounters()); + UpdateCounters(HugeAllocationCounters, NYT::NYTAlloc::GetHugeAllocationCounters()); + UpdateCounters(SystemAllocationCounters, NYT::NYTAlloc::GetSystemAllocationCounters()); + UpdateCounters(UndumpableAllocationCounters, NYT::NYTAlloc::GetUndumpableAllocationCounters()); + UpdateCounters(TimingEventCounters, NYT::NYTAlloc::GetTimingEventCounters()); + } + + private: + template <typename E> + static void InitCounters( + NYT::TEnumIndexedVector<E, TDynamicCounterPtr>& counters, + TDynamicCountersPtr group) { + for (auto c : NYT::TEnumTraits<E>::GetDomainValues()) { + counters[c] = group->GetCounter(NYT::TEnumTraits<E>::ToString(c)); + } + } + + template <typename E, size_t N> + static void InitCounters( + std::array<NYT::TEnumIndexedVector<E, TDynamicCounterPtr>, N>& counters, + TDynamicCountersPtr group) { + for (size_t i = 0; i < N; ++i) { + InitCounters(counters[i], group->GetSubgroup("rank", ToString(i))); + } + } + + template <typename E> + static void InitCounters( + NYT::TEnumIndexedVector<E, TTimingEventCounters>& counters, + TDynamicCountersPtr group) { + for (auto c : NYT::TEnumTraits<E>::GetDomainValues()) { + const auto& name = NYT::TEnumTraits<E>::ToString(c); + counters[c].Count = group->GetCounter(name + "_Count"); + counters[c].Size = group->GetCounter(name + "_Size"); + } + } + + template <typename E> + static void UpdateCounters( + NYT::TEnumIndexedVector<E, TDynamicCounterPtr>& counters, + const NYT::TEnumIndexedVector<E, ssize_t>& source) { + for (auto c : NYT::TEnumTraits<E>::GetDomainValues()) { + *counters[c] = source[c]; + } + } + + template <typename E, size_t N> + static void UpdateCounters( + std::array<NYT::TEnumIndexedVector<E, TDynamicCounterPtr>, N>& counters, + const std::array<NYT::TEnumIndexedVector<E, ssize_t>, N>& source) { + for (size_t i = 0; i < N; ++i) { + UpdateCounters(counters[i], source[i]); + } + } + + template <typename E> + static void UpdateCounters( + NYT::TEnumIndexedVector<E, TTimingEventCounters>& counters, + const NYT::TEnumIndexedVector<E, NYT::NYTAlloc::TTimingEventCounters>& source) { + for (auto c : NYT::TEnumTraits<E>::GetDomainValues()) { + *counters[c].Count = source[c].Count; + *counters[c].Size = source[c].Size; + } + } + }; + + struct TFakeAllocStats: public IAllocStats { + void Update() override { + } + }; + + std::unique_ptr<IAllocStats> CreateAllocStats(TDynamicCountersPtr group) { + const auto& info = NMalloc::MallocInfo(); TStringBuf name(info.Name); - + std::unique_ptr<IAllocStats> stats; - if (name.StartsWith("lf")) { + if (name.StartsWith("lf")) { stats = std::make_unique<TLfAllocStats>(std::move(group)); - } else if (name.StartsWith("yt")) { + } else if (name.StartsWith("yt")) { stats = std::make_unique<TYtAllocStats>(std::move(group)); } else if (name.StartsWith("tc")) { stats = std::move(CreateTcMallocStats(std::move(group))); - } + } return stats ? std::move(stats) : std::make_unique<TFakeAllocStats>(); - } - - class TMemStatsCollector: public TActorBootstrapped<TMemStatsCollector> { - private: - const TDuration Interval; - const std::unique_ptr<IAllocStats> AllocStats; - - public: - static constexpr EActivityType ActorActivityType() { - return ACTORLIB_STATS; - } - - TMemStatsCollector(TDuration interval, std::unique_ptr<IAllocStats> allocStats) - : Interval(interval) - , AllocStats(std::move(allocStats)) - { - } - - void Bootstrap(const TActorContext& ctx) { - Become(&TThis::StateWork); - ctx.Schedule(Interval, new TEvents::TEvWakeup()); - } - - private: - STFUNC(StateWork) { - switch (ev->GetTypeRewrite()) { - CFunc(TEvents::TSystem::Wakeup, HandleWakeup); - } - } - - void HandleWakeup(const TActorContext& ctx) noexcept { - AllocStats->Update(); - ctx.Schedule(Interval, new TEvents::TEvWakeup()); - } - }; + } + + class TMemStatsCollector: public TActorBootstrapped<TMemStatsCollector> { + private: + const TDuration Interval; + const std::unique_ptr<IAllocStats> AllocStats; + + public: + static constexpr EActivityType ActorActivityType() { + return ACTORLIB_STATS; + } + + TMemStatsCollector(TDuration interval, std::unique_ptr<IAllocStats> allocStats) + : Interval(interval) + , AllocStats(std::move(allocStats)) + { + } + + void Bootstrap(const TActorContext& ctx) { + Become(&TThis::StateWork); + ctx.Schedule(Interval, new TEvents::TEvWakeup()); + } + + private: + STFUNC(StateWork) { + switch (ev->GetTypeRewrite()) { + CFunc(TEvents::TSystem::Wakeup, HandleWakeup); + } + } + + void HandleWakeup(const TActorContext& ctx) noexcept { + AllocStats->Update(); + ctx.Schedule(Interval, new TEvents::TEvWakeup()); + } + }; struct TLfAllocState: public IAllocState { ui64 GetAllocatedMemoryEstimate() const override { @@ -283,13 +283,13 @@ namespace NKikimr { return state ? std::move(state) : std::make_unique<TFakeAllocState>(); } - } - - IActor* CreateMemStatsCollector(ui32 intervalSec, TDynamicCountersPtr counters) { - return new TMemStatsCollector( - TDuration::Seconds(intervalSec), - CreateAllocStats(GetServiceCounters(counters, "utils"))); - } + } + + IActor* CreateMemStatsCollector(ui32 intervalSec, TDynamicCountersPtr counters) { + return new TMemStatsCollector( + TDuration::Seconds(intervalSec), + CreateAllocStats(GetServiceCounters(counters, "utils"))); + } std::unique_ptr<IAllocState> TAllocState::AllocState = CreateAllocState(); @@ -305,4 +305,4 @@ namespace NKikimr { } return (double)procStat.AnonRss / procStat.CGroupMemLim; } -} +} diff --git a/ydb/core/mon_alloc/stats.h b/ydb/core/mon_alloc/stats.h index 23c5718b6b..a5528e5afd 100644 --- a/ydb/core/mon_alloc/stats.h +++ b/ydb/core/mon_alloc/stats.h @@ -1,17 +1,17 @@ -#pragma once - +#pragma once + #include <library/cpp/actors/core/defs.h> #include <library/cpp/actors/core/actor.h> - + #include <library/cpp/monlib/dynamic_counters/counters.h> - -namespace NKikimr { + +namespace NKikimr { struct IAllocStats { virtual ~IAllocStats() = default; virtual void Update() = 0; }; - NActors::IActor* CreateMemStatsCollector( + NActors::IActor* CreateMemStatsCollector( ui32 intervalSec, TIntrusivePtr<NMonitoring::TDynamicCounters> counters); @@ -27,4 +27,4 @@ namespace NKikimr { static ui64 GetAllocatedMemoryEstimate(); static double GetMemoryUsage(); }; -} +} diff --git a/ydb/core/mon_alloc/ya.make b/ydb/core/mon_alloc/ya.make index 75a655574f..972ea082f3 100644 --- a/ydb/core/mon_alloc/ya.make +++ b/ydb/core/mon_alloc/ya.make @@ -1,20 +1,20 @@ -LIBRARY() - +LIBRARY() + OWNER(g:kikimr) - -IF (PROFILE_MEMORY_ALLOCATIONS) + +IF (PROFILE_MEMORY_ALLOCATIONS) CFLAGS( -DPROFILE_MEMORY_ALLOCATIONS ) -ENDIF() - -SRCS( - monitor.cpp - profiler.cpp - stats.cpp -) - -PEERDIR( +ENDIF() + +SRCS( + monitor.cpp + profiler.cpp + stats.cpp +) + +PEERDIR( library/cpp/actors/core library/cpp/actors/prof library/cpp/html/pcdata @@ -25,8 +25,8 @@ PEERDIR( library/cpp/ytalloc/api ydb/core/base ydb/core/control -) - +) + IF (ALLOCATOR == "TCMALLOC_256K") SRCS( tcmalloc.cpp @@ -40,4 +40,4 @@ ELSE() ) ENDIF() -END() +END() diff --git a/ydb/core/protos/blockstore_config.proto b/ydb/core/protos/blockstore_config.proto index 7dc2f1d3cd..5cba383bfd 100644 --- a/ydb/core/protos/blockstore_config.proto +++ b/ydb/core/protos/blockstore_config.proto @@ -39,7 +39,7 @@ message TVolumeConfig { optional string ProjectId = 8; optional string FolderId = 9; optional string CloudId = 10; - optional uint32 TabletVersion = 11; + optional uint32 TabletVersion = 11; // Binary data for private use by BlockStore implementation (legacy, unused) optional bytes Opaque = 12; diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index b89044e595..d64169d4fc 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -284,7 +284,7 @@ message TLogConfig { optional bool AllowDropEntries = 8 [default = true]; optional bool UseLocalTimestamps = 9 [default = false]; optional string BackendFileName = 10; - optional string SysLogService = 11; + optional string SysLogService = 11; optional bool SysLogToStdErr = 12; // writes logs to stderr as well as in syslog optional TUAClientConfig UAClientConfig = 13; optional uint64 TimeThresholdMs = 14 [default = 1000]; diff --git a/ydb/core/protos/counters_schemeshard.proto b/ydb/core/protos/counters_schemeshard.proto index 2f5c67751e..a839915c98 100644 --- a/ydb/core/protos/counters_schemeshard.proto +++ b/ydb/core/protos/counters_schemeshard.proto @@ -86,12 +86,12 @@ enum ESimpleCounters { COUNTER_IN_FLIGHT_OPS_TxDropLock = 72 [(CounterOpts) = {Name: "InFlightOps/DropLock"}]; COUNTER_IN_FLIGHT_OPS_TxDropTableIndexAtMainTable = 73 [(CounterOpts) = {Name: "InFlightOps/DropTableIndexAtMainTable"}]; COUNTER_SYS_VIEW_PROCESSOR_COUNT = 74 [(CounterOpts) = {Name: "SysViewProcessors"}]; - - COUNTER_FILESTORE_COUNT = 75 [(CounterOpts) = {Name: "FileStores"}]; - COUNTER_FILESTORE_SHARD_COUNT = 76 [(CounterOpts) = {Name: "FileStoreShards"}]; - COUNTER_IN_FLIGHT_OPS_TxCreateFileStore = 77 [(CounterOpts) = {Name: "InFlightOps/CreateFileStore"}]; - COUNTER_IN_FLIGHT_OPS_TxAlterFileStore = 78 [(CounterOpts) = {Name: "InFlightOps/AlterFileStore"}]; - COUNTER_IN_FLIGHT_OPS_TxDropFileStore = 79 [(CounterOpts) = {Name: "InFlightOps/DropFileStore"}]; + + COUNTER_FILESTORE_COUNT = 75 [(CounterOpts) = {Name: "FileStores"}]; + COUNTER_FILESTORE_SHARD_COUNT = 76 [(CounterOpts) = {Name: "FileStoreShards"}]; + COUNTER_IN_FLIGHT_OPS_TxCreateFileStore = 77 [(CounterOpts) = {Name: "InFlightOps/CreateFileStore"}]; + COUNTER_IN_FLIGHT_OPS_TxAlterFileStore = 78 [(CounterOpts) = {Name: "InFlightOps/AlterFileStore"}]; + COUNTER_IN_FLIGHT_OPS_TxDropFileStore = 79 [(CounterOpts) = {Name: "InFlightOps/DropFileStore"}]; COUNTER_TTL_ENABLED_TABLE_COUNT = 80 [(CounterOpts) = {Name: "TTLEnabledTables"}]; @@ -199,10 +199,10 @@ enum ECumulativeCounters { COUNTER_FINISHED_OPS_TxAlterSolomonVolume = 43 [(CounterOpts) = {Name: "FinishedOps/AlterSolomonVolume"}]; COUNTER_FINISHED_OPS_TxDropLock = 44 [(CounterOpts) = {Name: "FinishedOps/DropLock"}]; COUNTER_FINISHED_OPS_TxDropTableIndexAtMainTable = 45 [(CounterOpts) = {Name: "FinishedOps/DropTableIndexAtMainTable"}]; - - COUNTER_FINISHED_OPS_TxCreateFileStore = 46 [(CounterOpts) = {Name: "FinishedOps/CreateFileStore"}]; - COUNTER_FINISHED_OPS_TxAlterFileStore = 47 [(CounterOpts) = {Name: "FinishedOps/AlterFileStore"}]; - COUNTER_FINISHED_OPS_TxDropFileStore = 48 [(CounterOpts) = {Name: "FinishedOps/DropFileStore"}]; + + COUNTER_FINISHED_OPS_TxCreateFileStore = 46 [(CounterOpts) = {Name: "FinishedOps/CreateFileStore"}]; + COUNTER_FINISHED_OPS_TxAlterFileStore = 47 [(CounterOpts) = {Name: "FinishedOps/AlterFileStore"}]; + COUNTER_FINISHED_OPS_TxDropFileStore = 48 [(CounterOpts) = {Name: "FinishedOps/DropFileStore"}]; COUNTER_FINISHED_OPS_TxRestore = 49 [(CounterOpts) = {Name: "FinishedOps/Restore"}]; @@ -328,8 +328,8 @@ enum ETxTypes { TXTYPE_RUN_CONDITIONAL_ERASE = 44 [(TxTypeOpts) = {Name: "TxRunConditionalErase"}]; TXTYPE_STORE_PARTITION_STATS = 45 [(TxTypeOpts) = {Name: "TxStorePartitionStats"}]; - - TXTYPE_FILESTORE_CONFIG_RESULT = 46 [(TxTypeOpts) = {Name: "TxFileStoreConfigResult"}]; + + TXTYPE_FILESTORE_CONFIG_RESULT = 46 [(TxTypeOpts) = {Name: "TxFileStoreConfigResult"}]; TXTYPE_MAKEBILL_INDEX_BUILD = 47 [(TxTypeOpts) = {Name: "TxBillingIndexBuild"}]; diff --git a/ydb/core/protos/filestore_config.proto b/ydb/core/protos/filestore_config.proto index 2de22e2280..6154eb2039 100644 --- a/ydb/core/protos/filestore_config.proto +++ b/ydb/core/protos/filestore_config.proto @@ -1,6 +1,6 @@ -package NKikimrFileStore; -option java_package = "ru.yandex.kikimr.proto"; - +package NKikimrFileStore; +option java_package = "ru.yandex.kikimr.proto"; + message TChannelProfile { // storage settings optional string PoolKind = 1; @@ -10,24 +10,24 @@ message TChannelProfile { optional double WriteIops = 5; // required iops for write requests optional double WriteBandwidth = 6; // required bandwidth (in bytes/sec) for write requests optional uint32 DataKind = 7; // the kind of data to be stored, e.g. mixed/merged/etc. -} - -message TConfig { - // Version number for atomic updates - optional uint32 Version = 1; - - // FileStore information - optional string FileSystemId = 10; - optional string ProjectId = 11; - optional string FolderId = 12; - optional string CloudId = 13; - - optional uint32 BlockSize = 14; - optional uint64 BlocksCount = 15; - - optional uint64 CreationTs = 16; - optional uint64 AlterTs = 17; - +} + +message TConfig { + // Version number for atomic updates + optional uint32 Version = 1; + + // FileStore information + optional string FileSystemId = 10; + optional string ProjectId = 11; + optional string FolderId = 12; + optional string CloudId = 13; + + optional uint32 BlockSize = 14; + optional uint64 BlocksCount = 15; + + optional uint64 CreationTs = 16; + optional uint64 AlterTs = 17; + optional uint32 RangeIdHasherType = 18; repeated TChannelProfile ExplicitChannelProfiles = 30; @@ -41,22 +41,22 @@ message TConfig { optional uint32 PerformanceProfileMaxWriteIops = 36; optional uint32 NodesCount = 40; -} - -message TUpdateConfig { - optional uint64 TxId = 1; - optional TConfig Config = 2; -} - -enum EStatus { - OK = 0; - ERROR = 1; - ERROR_BAD_VERSION = 2; - ERROR_UPDATE_IN_PROGRESS = 3; -} - -message TUpdateConfigResponse { - optional uint64 TxId = 1; - optional uint64 Origin = 2; - optional EStatus Status = 3; -} +} + +message TUpdateConfig { + optional uint64 TxId = 1; + optional TConfig Config = 2; +} + +enum EStatus { + OK = 0; + ERROR = 1; + ERROR_BAD_VERSION = 2; + ERROR_UPDATE_IN_PROGRESS = 3; +} + +message TUpdateConfigResponse { + optional uint64 TxId = 1; + optional uint64 Origin = 2; + optional EStatus Status = 3; +} diff --git a/ydb/core/protos/flat_scheme_op.proto b/ydb/core/protos/flat_scheme_op.proto index abc8e493fe..33e598c1c2 100644 --- a/ydb/core/protos/flat_scheme_op.proto +++ b/ydb/core/protos/flat_scheme_op.proto @@ -305,7 +305,7 @@ message TTTLSettings { message TEnabled { optional string ColumnName = 1; - optional uint32 ExpireAfterSeconds = 2; + optional uint32 ExpireAfterSeconds = 2; optional EUnit ColumnUnit = 3; optional TSysSettings SysSettings = 4; } @@ -948,14 +948,14 @@ message TBlockStoreVolumeDescription { optional uint64 TokenVersion = 8; // do not set } -message TFileStoreDescription { - optional string Name = 1; // mandatory - optional uint64 PathId = 2; - optional uint64 IndexTabletId = 3; // do not set - optional NKikimrFileStore.TConfig Config = 4; // mandatory - optional uint64 Version = 5; // do not set -} - +message TFileStoreDescription { + optional string Name = 1; // mandatory + optional uint64 PathId = 2; + optional uint64 IndexTabletId = 3; // do not set + optional NKikimrFileStore.TConfig Config = 4; // mandatory + optional uint64 Version = 5; // do not set +} + message TKesusDescription { optional string Name = 1; // mandatory optional uint64 PathId = 2; @@ -1130,10 +1130,10 @@ enum EOperationType { ESchemeOpDropTableIndexAtMainTable = 49; ESchemeOpCancelIndexBuild = 50; - - ESchemeOpCreateFileStore = 51; - ESchemeOpAlterFileStore = 52; - ESchemeOpDropFileStore = 53; + + ESchemeOpCreateFileStore = 51; + ESchemeOpAlterFileStore = 52; + ESchemeOpDropFileStore = 53; ESchemeOpRestore = 54; @@ -1258,8 +1258,8 @@ message TModifyScheme { optional TAlterSolomonVolume AlterSolomonVolume = 33; optional TDropIndex DropIndex = 34; optional TIndexBuildControl CancelIndexBuild = 35; - optional TFileStoreDescription CreateFileStore = 37; - optional TFileStoreDescription AlterFileStore = 38; + optional TFileStoreDescription CreateFileStore = 37; + optional TFileStoreDescription AlterFileStore = 38; optional TRestoreTask Restore = 39; optional TColumnStoreDescription CreateColumnStore = 40; optional TColumnTableDescription CreateColumnTable = 41; @@ -1320,7 +1320,7 @@ enum EPathType { EPathTypeSolomonVolume = 8; EPathTypeTableIndex = 9; // Used for abstract index EPathTypeExtSubDomain = 10; - EPathTypeFileStore = 11; + EPathTypeFileStore = 11; EPathTypeColumnStore = 12; EPathTypeColumnTable = 13; EPathTypeCdcStream = 14; @@ -1365,7 +1365,7 @@ message TPathVersion { optional uint64 KesusVersion = 12; optional uint64 RTMRVersion = 13; optional uint64 SolomonVersion = 14; - optional uint64 FileStoreVersion = 15; + optional uint64 FileStoreVersion = 15; optional uint64 ColumnStoreVersion = 16; optional uint64 ColumnTableVersion = 17; optional uint64 ColumnTableShardingVersion = 18; @@ -1454,7 +1454,7 @@ message TPathDescription { optional TIndexDescription TableIndex = 17; repeated NKikimrTabletBase.TMetrics TablePartitionMetrics = 18; repeated uint64 AbandonedTenantsSchemeShards = 19; - optional TFileStoreDescription FileStoreDescription = 20; + optional TFileStoreDescription FileStoreDescription = 20; optional TColumnStoreDescription ColumnStoreDescription = 21; optional TColumnTableDescription ColumnTableDescription = 22; optional TCdcStreamDescription CdcStreamDescription = 23; diff --git a/ydb/core/protos/services.proto b/ydb/core/protos/services.proto index a47e01e885..c17c8a7dc3 100644 --- a/ydb/core/protos/services.proto +++ b/ydb/core/protos/services.proto @@ -306,7 +306,7 @@ enum EServiceKikimr { }; message TActivity { - + // Must be consistent with IActor::EActorActivity in ActorLib's part. // NOTE: all values are used as indices in counters array. // NOTE: numeric values can be changed and must be used only locally (inside one process), @@ -779,14 +779,14 @@ message TActivity { YT_TABLE_WRITER_ACTOR = 464; SCHEME_BOARD_SUBSCRIBER_PROXY_ACTOR = 465; S3_WRAPPER_ACTOR = 466; - FILESTORE_SCHEMESHARD = 467; - FILESTORE_SERVICE = 468; - FILESTORE_SERVICE_WORKER = 469; + FILESTORE_SCHEMESHARD = 467; + FILESTORE_SERVICE = 468; + FILESTORE_SERVICE_WORKER = 469; TX_OLAPSHARD_ACTOR = 470; - FILESTORE_TABLET = 471; - FILESTORE_TABLET_WORKER = 472; - FILESTORE_TABLET_PROXY = 473; - FILESTORE_SS_PROXY = 474; + FILESTORE_TABLET = 471; + FILESTORE_TABLET_WORKER = 472; + FILESTORE_TABLET_PROXY = 473; + FILESTORE_SS_PROXY = 474; IMPORT_S3_DOWNLOADER_ACTOR = 475; MEMORY_TRACKER = 476; TX_COLUMNSHARD_ACTOR = 477; diff --git a/ydb/core/protos/tablet.proto b/ydb/core/protos/tablet.proto index eb078bd9c9..f0bec238e7 100644 --- a/ydb/core/protos/tablet.proto +++ b/ydb/core/protos/tablet.proto @@ -33,28 +33,28 @@ message TTabletTypes { TxAllocator = 23; PersQueueReadBalancer = 24; BlockStoreVolume = 25; - BlockStorePartition = 26; + BlockStorePartition = 26; TenantSlotBroker = 27; Console = 28; Kesus = 29; BlockStorePartition2 = 30; - BlockStoreDiskRegistry = 31; + BlockStoreDiskRegistry = 31; SysViewProcessor = 32; - FileStore = 33; - OlapShard = 34; - ColumnShard = 35; + FileStore = 33; + OlapShard = 34; + ColumnShard = 35; TestShard = 36; SequenceShard = 37; ReplicationController = 38; - // when adding a new tablet type and keeping parse compatibility with the old version - // rename existing reserved item to desired one, and add new reserved item to - // the end of reserved list - Reserved39 = 39; + // when adding a new tablet type and keeping parse compatibility with the old version + // rename existing reserved item to desired one, and add new reserved item to + // the end of reserved list + Reserved39 = 39; Reserved40 = 40; Reserved41 = 41; Reserved42 = 42; - + UserTypeStart = 255; TypeInvalid = -1; } diff --git a/ydb/core/protos/ya.make b/ydb/core/protos/ya.make index 2c0da07f46..70bb65514c 100644 --- a/ydb/core/protos/ya.make +++ b/ydb/core/protos/ya.make @@ -25,7 +25,7 @@ SRCS( blobstorage_vdisk_internal.proto blobstorage_config.proto blockstore_config.proto - filestore_config.proto + filestore_config.proto bootstrapper.proto change_exchange.proto channel_purpose.proto diff --git a/ydb/core/tablet_flat/flat_cxx_database.h b/ydb/core/tablet_flat/flat_cxx_database.h index 504b38ae6f..27a260bcb2 100644 --- a/ydb/core/tablet_flat/flat_cxx_database.h +++ b/ydb/core/tablet_flat/flat_cxx_database.h @@ -257,10 +257,10 @@ public: return static_cast<typename NSchemeTypeMapper<NScheme::NTypeIds::String>::Type>(value); } - static typename NSchemeTypeMapper<NScheme::NTypeIds::String>::Type ConvertFrom(const TStringBuf& value) { + static typename NSchemeTypeMapper<NScheme::NTypeIds::String>::Type ConvertFrom(const TStringBuf& value) { return static_cast<typename NSchemeTypeMapper<NScheme::NTypeIds::String>::Type>(TString(value)); - } - + } + static typename NSchemeTypeMapper<NScheme::NTypeIds::String>::Type ConvertFrom(const ::google::protobuf::Message& value) { return static_cast<typename NSchemeTypeMapper<NScheme::NTypeIds::String>::Type>(value.SerializeAsString()); } @@ -1194,8 +1194,8 @@ struct Schema { }; template <typename, typename, typename, typename> - class RangeKeyIterator; - + class RangeKeyIterator; + template <typename IteratorType, typename TableType, typename... MinKeyValuesTypes, typename... MaxKeyValuesTypes> class RangeKeyIterator<IteratorType, TableType, std::tuple<MinKeyValuesTypes...>, std::tuple<MaxKeyValuesTypes...>> : public KeyIterator<IteratorType, RangeKeyIterator<IteratorType, TableType, std::tuple<MinKeyValuesTypes...>, std::tuple<MaxKeyValuesTypes...>>> @@ -1206,7 +1206,7 @@ struct Schema { using MaxKeyValuesType = std::tuple<MaxKeyValuesTypes...>; using MaxKeyColumnsType = typename first_n_of<sizeof...(MaxKeyValuesTypes), typename TableType::TKey::KeyColumnsType>::type; using Iterator = KeyIterator<IteratorType, RangeKeyIterator<IteratorType, TableType, MinKeyValuesType, MaxKeyValuesType>>; - + static constexpr auto FullKeySize = std::tuple_size<typename TableType::TKey::KeyColumnsType>::value; RangeKeyIterator(TToughDb& database, diff --git a/ydb/core/testlib/actors/test_runtime.cpp b/ydb/core/testlib/actors/test_runtime.cpp index 88d03e4632..63f0436bff 100644 --- a/ydb/core/testlib/actors/test_runtime.cpp +++ b/ydb/core/testlib/actors/test_runtime.cpp @@ -102,7 +102,7 @@ namespace NActors { const auto* app0 = App0.Get(); if (!SingleSysEnv) { const TIntrusivePtr<NMonitoring::TDynamicCounters> profilerCounters = NKikimr::GetServiceCounters(node->DynamicCounters, "utils"); - TActorSetupCmd profilerSetup(CreateProfilerActor(profilerCounters, "."), TMailboxType::Simple, 0); + TActorSetupCmd profilerSetup(CreateProfilerActor(profilerCounters, "."), TMailboxType::Simple, 0); node->LocalServices.push_back(std::pair<TActorId, TActorSetupCmd>(MakeProfilerID(FirstNodeId + nodeIndex), profilerSetup)); } diff --git a/ydb/core/tx/schemeshard/schemeshard__delete_tablet_reply.cpp b/ydb/core/tx/schemeshard/schemeshard__delete_tablet_reply.cpp index ffe774fb38..855553cddc 100644 --- a/ydb/core/tx/schemeshard/schemeshard__delete_tablet_reply.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__delete_tablet_reply.cpp @@ -74,9 +74,9 @@ struct TSchemeShard::TTxDeleteTabletReply : public TSchemeShard::TRwTxBase { case ETabletType::BlockStorePartition2: Self->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION2_SHARD_COUNT].Sub(1); break; - case ETabletType::FileStore: + case ETabletType::FileStore: Self->TabletCounters->Simple()[COUNTER_FILESTORE_SHARD_COUNT].Sub(1); - break; + break; case ETabletType::Kesus: Self->TabletCounters->Simple()[COUNTER_KESUS_SHARD_COUNT].Sub(1); break; diff --git a/ydb/core/tx/schemeshard/schemeshard__init.cpp b/ydb/core/tx/schemeshard/schemeshard__init.cpp index 75e8e7f05f..650506549e 100644 --- a/ydb/core/tx/schemeshard/schemeshard__init.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__init.cpp @@ -1911,7 +1911,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> { // Read shards (any tipe of tablets) THashMap<TPathId, TShardIdx> pqBalancers; // pathId -> shardIdx THashMap<TPathId, TShardIdx> nbsVolumeShards; // pathId -> shardIdx - THashMap<TPathId, TShardIdx> fileStoreShards; // pathId -> shardIdx + THashMap<TPathId, TShardIdx> fileStoreShards; // pathId -> shardIdx THashMap<TPathId, TShardIdx> kesusShards; // pathId -> shardIdx THashMap<TPathId, TVector<TShardIdx>> olapColumnShards; { @@ -2968,68 +2968,68 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> { } } - // Read FileStoreInfos - { - auto rowset = db.Table<Schema::FileStoreInfos>().Range().Select(); - if (!rowset.IsReady()) - return false; - - while (!rowset.EndOfSet()) { - TLocalPathId localPathId = rowset.GetValue<Schema::FileStoreInfos::PathId>(); - TPathId pathId(selfId, localPathId); - - TFileStoreInfo::TPtr fs = new TFileStoreInfo(); - { - auto cfg = rowset.GetValue<Schema::FileStoreInfos::Config>(); - bool parseOk = ParseFromStringNoSizeLimit(fs->Config, cfg); - Y_VERIFY(parseOk); - fs->Version = rowset.GetValueOrDefault<Schema::FileStoreInfos::Version>(); - } - Self->FileStoreInfos[pathId] = fs; + // Read FileStoreInfos + { + auto rowset = db.Table<Schema::FileStoreInfos>().Range().Select(); + if (!rowset.IsReady()) + return false; + + while (!rowset.EndOfSet()) { + TLocalPathId localPathId = rowset.GetValue<Schema::FileStoreInfos::PathId>(); + TPathId pathId(selfId, localPathId); + + TFileStoreInfo::TPtr fs = new TFileStoreInfo(); + { + auto cfg = rowset.GetValue<Schema::FileStoreInfos::Config>(); + bool parseOk = ParseFromStringNoSizeLimit(fs->Config, cfg); + Y_VERIFY(parseOk); + fs->Version = rowset.GetValueOrDefault<Schema::FileStoreInfos::Version>(); + } + Self->FileStoreInfos[pathId] = fs; Self->IncrementPathDbRefCount(pathId); - - auto it = fileStoreShards.find(pathId); - if (it != fileStoreShards.end()) { - TShardIdx shardIdx = it->second; - const auto& shard = Self->ShardInfos[shardIdx]; - fs->IndexShardIdx = shardIdx; - fs->IndexTabletId = shard.TabletID; - } - - if (!rowset.Next()) - return false; - } - - // Read FileStoreAlters - { - auto rowset = db.Table<Schema::FileStoreAlters>().Range().Select(); - if (!rowset.IsReady()) - return false; - - while (!rowset.EndOfSet()) { - TLocalPathId localPathId = rowset.GetValue<Schema::FileStoreAlters::PathId>(); - TPathId pathId(selfId, localPathId); - - auto it = Self->FileStoreInfos.find(pathId); - Y_VERIFY(it != Self->FileStoreInfos.end()); - - TFileStoreInfo::TPtr fs = it->second; - Y_VERIFY(fs); - - { + + auto it = fileStoreShards.find(pathId); + if (it != fileStoreShards.end()) { + TShardIdx shardIdx = it->second; + const auto& shard = Self->ShardInfos[shardIdx]; + fs->IndexShardIdx = shardIdx; + fs->IndexTabletId = shard.TabletID; + } + + if (!rowset.Next()) + return false; + } + + // Read FileStoreAlters + { + auto rowset = db.Table<Schema::FileStoreAlters>().Range().Select(); + if (!rowset.IsReady()) + return false; + + while (!rowset.EndOfSet()) { + TLocalPathId localPathId = rowset.GetValue<Schema::FileStoreAlters::PathId>(); + TPathId pathId(selfId, localPathId); + + auto it = Self->FileStoreInfos.find(pathId); + Y_VERIFY(it != Self->FileStoreInfos.end()); + + TFileStoreInfo::TPtr fs = it->second; + Y_VERIFY(fs); + + { fs->AlterConfig = MakeHolder<NKikimrFileStore::TConfig>(); - auto cfg = rowset.GetValue<Schema::FileStoreAlters::Config>(); - bool parseOk = ParseFromStringNoSizeLimit(*fs->AlterConfig, cfg); - Y_VERIFY(parseOk); - fs->AlterVersion = rowset.GetValue<Schema::FileStoreAlters::Version>(); - } - - if (!rowset.Next()) - return false; - } - } - } - + auto cfg = rowset.GetValue<Schema::FileStoreAlters::Config>(); + bool parseOk = ParseFromStringNoSizeLimit(*fs->AlterConfig, cfg); + Y_VERIFY(parseOk); + fs->AlterVersion = rowset.GetValue<Schema::FileStoreAlters::Version>(); + } + + if (!rowset.Next()) + return false; + } + } + } + // Read KesusInfos { TKesusInfosRows kesusRows; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation.cpp b/ydb/core/tx/schemeshard/schemeshard__operation.cpp index 52b8e434f7..daf1218bcf 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation.cpp @@ -586,8 +586,8 @@ TOperation::TSplitTransactionsResult TOperation::SplitIntoTransactions(const TTx targetName = tx.GetCreateBlockStoreVolume().GetName(); break; case NKikimrSchemeOp::EOperationType::ESchemeOpCreateFileStore: - targetName = tx.GetCreateFileStore().GetName(); - break; + targetName = tx.GetCreateFileStore().GetName(); + break; case NKikimrSchemeOp::EOperationType::ESchemeOpCreateKesus: targetName = tx.GetKesus().GetName(); break; @@ -673,8 +673,8 @@ TOperation::TSplitTransactionsResult TOperation::SplitIntoTransactions(const TTx create.MutableCreateBlockStoreVolume()->SetName(name); break; case NKikimrSchemeOp::EOperationType::ESchemeOpCreateFileStore: - create.MutableCreateFileStore()->SetName(name); - break; + create.MutableCreateFileStore()->SetName(name); + break; case NKikimrSchemeOp::EOperationType::ESchemeOpCreateKesus: create.MutableKesus()->SetName(name); break; @@ -854,24 +854,24 @@ ISubOperationBase::TPtr TOperation::RestorePart(TTxState::ETxType txType, TTxSta case TTxState::ETxType::TxAlterSolomonVolume: return CreateAlterSolomon(NextPartId(), txState); - // BlockStore - case TTxState::ETxType::TxCreateBlockStoreVolume: - return CreateNewBSV(NextPartId(), txState); - case TTxState::ETxType::TxAssignBlockStoreVolume: - return CreateAssignBSV(NextPartId(), txState); - case TTxState::ETxType::TxAlterBlockStoreVolume: - return CreateAlterBSV(NextPartId(), txState); - case TTxState::ETxType::TxDropBlockStoreVolume: - return CreateDropBSV(NextPartId(), txState); - - // FileStore - case TTxState::ETxType::TxCreateFileStore: - return CreateNewFileStore(NextPartId(), txState); - case TTxState::ETxType::TxAlterFileStore: - return CreateAlterFileStore(NextPartId(), txState); - case TTxState::ETxType::TxDropFileStore: - return CreateDropFileStore(NextPartId(), txState); - + // BlockStore + case TTxState::ETxType::TxCreateBlockStoreVolume: + return CreateNewBSV(NextPartId(), txState); + case TTxState::ETxType::TxAssignBlockStoreVolume: + return CreateAssignBSV(NextPartId(), txState); + case TTxState::ETxType::TxAlterBlockStoreVolume: + return CreateAlterBSV(NextPartId(), txState); + case TTxState::ETxType::TxDropBlockStoreVolume: + return CreateDropBSV(NextPartId(), txState); + + // FileStore + case TTxState::ETxType::TxCreateFileStore: + return CreateNewFileStore(NextPartId(), txState); + case TTxState::ETxType::TxAlterFileStore: + return CreateAlterFileStore(NextPartId(), txState); + case TTxState::ETxType::TxDropFileStore: + return CreateDropFileStore(NextPartId(), txState); + // CDC case TTxState::ETxType::TxCreateCdcStream: return CreateNewCdcStreamImpl(NextPartId(), txState); @@ -1006,24 +1006,24 @@ ISubOperationBase::TPtr TOperation::ConstructPart(NKikimrSchemeOp::EOperationTyp case NKikimrSchemeOp::EOperationType::ESchemeOpDropLock: return DropLock(NextPartId(), tx); - // BlockStore + // BlockStore case NKikimrSchemeOp::EOperationType::ESchemeOpCreateBlockStoreVolume: - return CreateNewBSV(NextPartId(), tx); + return CreateNewBSV(NextPartId(), tx); case NKikimrSchemeOp::EOperationType::ESchemeOpAssignBlockStoreVolume: - return CreateAssignBSV(NextPartId(), tx); + return CreateAssignBSV(NextPartId(), tx); case NKikimrSchemeOp::EOperationType::ESchemeOpAlterBlockStoreVolume: - return CreateAlterBSV(NextPartId(), tx); + return CreateAlterBSV(NextPartId(), tx); case NKikimrSchemeOp::EOperationType::ESchemeOpDropBlockStoreVolume: - return CreateDropBSV(NextPartId(), tx); - - // FileStore + return CreateDropBSV(NextPartId(), tx); + + // FileStore case NKikimrSchemeOp::EOperationType::ESchemeOpCreateFileStore: - return CreateNewFileStore(NextPartId(), tx); + return CreateNewFileStore(NextPartId(), tx); case NKikimrSchemeOp::EOperationType::ESchemeOpAlterFileStore: - return CreateAlterFileStore(NextPartId(), tx); + return CreateAlterFileStore(NextPartId(), tx); case NKikimrSchemeOp::EOperationType::ESchemeOpDropFileStore: - return CreateDropFileStore(NextPartId(), tx); - + return CreateDropFileStore(NextPartId(), tx); + // Login case NKikimrSchemeOp::EOperationType::ESchemeOpAlterLogin: return CreateAlterLogin(NextPartId(), tx); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp index ca1717ae6a..ee2a3fb3e5 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp @@ -1,289 +1,289 @@ -#include "schemeshard__operation_part.h" -#include "schemeshard__operation_common.h" -#include "schemeshard_impl.h" - +#include "schemeshard__operation_part.h" +#include "schemeshard__operation_common.h" +#include "schemeshard_impl.h" + #include <ydb/core/base/subdomain.h> #include <ydb/core/mind/hive/hive.h> - -namespace { - -using namespace NKikimr; + +namespace { + +using namespace NKikimr; using namespace NSchemeShard; - -//////////////////////////////////////////////////////////////////////////////// - -class TConfigureParts: public TSubOperationState { -private: - const TOperationId OperationId; - + +//////////////////////////////////////////////////////////////////////////////// + +class TConfigureParts: public TSubOperationState { +private: + const TOperationId OperationId; + TString DebugHint() const override { - return TStringBuilder() - << "TAlterFileStore::TConfigureParts" - << " operationId#" << OperationId; - } - -public: - TConfigureParts(TOperationId id) - : OperationId(id) - { - IgnoreMessages(DebugHint(), {}); - } - - bool HandleReply( - TEvFileStore::TEvUpdateConfigResponse::TPtr& ev, - TOperationContext& context) override - { - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " HandleReply TEvUpdateConfigResponse" - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - Y_VERIFY(txState); + return TStringBuilder() + << "TAlterFileStore::TConfigureParts" + << " operationId#" << OperationId; + } + +public: + TConfigureParts(TOperationId id) + : OperationId(id) + { + IgnoreMessages(DebugHint(), {}); + } + + bool HandleReply( + TEvFileStore::TEvUpdateConfigResponse::TPtr& ev, + TOperationContext& context) override + { + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " HandleReply TEvUpdateConfigResponse" + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + Y_VERIFY(txState); Y_VERIFY(txState->TxType == TTxState::TxAlterFileStore, "invalid tx type %u", txState->TxType); Y_VERIFY(txState->State == TTxState::ConfigureParts, "invalid tx state %u", txState->State); - - auto tabletId = TTabletId(ev->Get()->Record.GetOrigin()); - auto status = ev->Get()->Record.GetStatus(); - - // Schemeshard never sends invalid or outdated configs - Y_VERIFY_S(status == NKikimrFileStore::OK || status == NKikimrFileStore::ERROR_UPDATE_IN_PROGRESS, - "Unexpected error in UpdateConfigResponse" - << ", status: " << NKikimrFileStore::EStatus_Name(status) - << ", tx: " << OperationId - << ", tablet: " << tabletId - << ", at schemeshard: " << ssId); - - if (status == NKikimrFileStore::ERROR_UPDATE_IN_PROGRESS) { - LOG_ERROR_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " Reconfiguration is in progress. We'll try to finish it later." - << " tx " << OperationId - << " tablet " << tabletId); - return false; - } - + + auto tabletId = TTabletId(ev->Get()->Record.GetOrigin()); + auto status = ev->Get()->Record.GetStatus(); + + // Schemeshard never sends invalid or outdated configs + Y_VERIFY_S(status == NKikimrFileStore::OK || status == NKikimrFileStore::ERROR_UPDATE_IN_PROGRESS, + "Unexpected error in UpdateConfigResponse" + << ", status: " << NKikimrFileStore::EStatus_Name(status) + << ", tx: " << OperationId + << ", tablet: " << tabletId + << ", at schemeshard: " << ssId); + + if (status == NKikimrFileStore::ERROR_UPDATE_IN_PROGRESS) { + LOG_ERROR_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " Reconfiguration is in progress. We'll try to finish it later." + << " tx " << OperationId + << " tablet " << tabletId); + return false; + } + TShardIdx idx = context.SS->MustGetShardIdx(tabletId); - txState->ShardsInProgress.erase(idx); - - context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); - - if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); - context.SS->ChangeTxState(db, OperationId, TTxState::Propose); - context.OnComplete.ActivateTx(OperationId); - return true; - } - - return false; - } - - bool ProgressState(TOperationContext& context) override { - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " ProgressState" - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - Y_VERIFY(txState); - Y_VERIFY(txState->TxType == TTxState::TxAlterFileStore); - Y_VERIFY(!txState->Shards.empty()); - - txState->ClearShardsInProgress(); - - auto fs = context.SS->FileStoreInfos[txState->TargetPathId]; - Y_VERIFY_S(fs, "FileStore info is null. PathId: " << txState->TargetPathId); - - Y_VERIFY(txState->Shards.size() == 1); - for (const auto& shard: txState->Shards) { - Y_VERIFY(shard.TabletType == ETabletType::FileStore); - auto shardIdx = shard.Idx; - auto tabletId = context.SS->ShardInfos[shardIdx].TabletID; - - TAutoPtr<TEvFileStore::TEvUpdateConfig> event(new TEvFileStore::TEvUpdateConfig()); - event->Record.SetTxId(ui64(OperationId.GetTxId())); - event->Record.MutableConfig()->CopyFrom(*fs->AlterConfig); - event->Record.MutableConfig()->SetVersion(fs->AlterVersion); - - context.OnComplete.BindMsgToPipe(OperationId, tabletId, shardIdx, event.Release()); - - // Wait for results from this shard - txState->ShardsInProgress.insert(shardIdx); - } - - return false; - } -}; - -//////////////////////////////////////////////////////////////////////////////// - -class TPropose: public TSubOperationState { -private: - const TOperationId OperationId; - + txState->ShardsInProgress.erase(idx); + + context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); + + if (txState->ShardsInProgress.empty()) { + NIceDb::TNiceDb db(context.Txc.DB); + context.SS->ChangeTxState(db, OperationId, TTxState::Propose); + context.OnComplete.ActivateTx(OperationId); + return true; + } + + return false; + } + + bool ProgressState(TOperationContext& context) override { + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " ProgressState" + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + Y_VERIFY(txState); + Y_VERIFY(txState->TxType == TTxState::TxAlterFileStore); + Y_VERIFY(!txState->Shards.empty()); + + txState->ClearShardsInProgress(); + + auto fs = context.SS->FileStoreInfos[txState->TargetPathId]; + Y_VERIFY_S(fs, "FileStore info is null. PathId: " << txState->TargetPathId); + + Y_VERIFY(txState->Shards.size() == 1); + for (const auto& shard: txState->Shards) { + Y_VERIFY(shard.TabletType == ETabletType::FileStore); + auto shardIdx = shard.Idx; + auto tabletId = context.SS->ShardInfos[shardIdx].TabletID; + + TAutoPtr<TEvFileStore::TEvUpdateConfig> event(new TEvFileStore::TEvUpdateConfig()); + event->Record.SetTxId(ui64(OperationId.GetTxId())); + event->Record.MutableConfig()->CopyFrom(*fs->AlterConfig); + event->Record.MutableConfig()->SetVersion(fs->AlterVersion); + + context.OnComplete.BindMsgToPipe(OperationId, tabletId, shardIdx, event.Release()); + + // Wait for results from this shard + txState->ShardsInProgress.insert(shardIdx); + } + + return false; + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class TPropose: public TSubOperationState { +private: + const TOperationId OperationId; + TString DebugHint() const override { - return TStringBuilder() - << "TAlterFileStore::TPropose" - << " operationId#" << OperationId; - } - -public: - TPropose(TOperationId id) - : OperationId(id) - { - IgnoreMessages(DebugHint(), {}); - } - - bool HandleReply( - TEvPrivate::TEvOperationPlan::TPtr& ev, - TOperationContext& context) override - { - const auto step = TStepId(ev->Get()->StepId); - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " HandleReply TEvOperationPlan" - << ", step: " << step - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - if (!txState) { - return false; - } - - Y_VERIFY(txState->TxType == TTxState::TxAlterFileStore); - TPathId pathId = txState->TargetPathId; - - auto fs = context.SS->FileStoreInfos.at(pathId); - Y_VERIFY_S(fs, "FileStore info is null. PathId: " << pathId); - - TPathElement::TPtr path = context.SS->PathsById.at(pathId); - path->PathState = TPathElement::EPathState::EPathStateNoChanges; - path->StepCreated = step; - - NIceDb::TNiceDb db(context.Txc.DB); - context.SS->PersistCreateStep(db, pathId, step); - - fs->FinishAlter(); - - context.SS->PersistFileStoreInfo(db, pathId, fs); - context.SS->PersistRemoveFileStoreAlter(db, pathId); - - context.SS->ClearDescribePathCaches(path); - context.OnComplete.PublishToSchemeBoard(OperationId, pathId); - - context.OnComplete.DoneOperation(OperationId); - return false; - } - - bool ProgressState(TOperationContext& context) override { - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " ProgressState" - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - Y_VERIFY(txState); - Y_VERIFY(txState->TxType == TTxState::TxAlterFileStore); - - context.OnComplete.ProposeToCoordinator(OperationId, txState->TargetPathId, TStepId(0)); - return false; - } -}; - -//////////////////////////////////////////////////////////////////////////////// - -class TAlterFileStore: public TSubOperation { -private: - const TOperationId OperationId; - const TTxTransaction Transaction; - - TTxState::ETxState State = TTxState::Invalid; - -public: - TAlterFileStore(TOperationId id, const TTxTransaction& tx) - : OperationId(id) - , Transaction(tx) - { - } - - TAlterFileStore(TOperationId id, TTxState::ETxState state) - : OperationId(id) - , State(state) - { - SetState(SelectStateFunc(state)); - } - - THolder<TProposeResponse> Propose( - const TString& owner, - TOperationContext& context) override; - - void AbortPropose(TOperationContext&) override { - Y_FAIL("no AbortPropose for TAlterFileStore"); - } - - void AbortUnsafe(TTxId forceDropTxId, TOperationContext& context) override { - LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "TAlterFileStore AbortUnsafe" - << ", opId: " << OperationId - << ", forceDropId: " << forceDropTxId - << ", at schemeshard: " << context.SS->TabletID()); - - context.OnComplete.DoneOperation(OperationId); - } - - void StateDone(TOperationContext& context) override { - State = NextState(State); - - if (State != TTxState::Invalid) { - SetState(SelectStateFunc(State)); - context.OnComplete.ActivateTx(OperationId); - } - } - -private: - TTxState::ETxState NextState() { + return TStringBuilder() + << "TAlterFileStore::TPropose" + << " operationId#" << OperationId; + } + +public: + TPropose(TOperationId id) + : OperationId(id) + { + IgnoreMessages(DebugHint(), {}); + } + + bool HandleReply( + TEvPrivate::TEvOperationPlan::TPtr& ev, + TOperationContext& context) override + { + const auto step = TStepId(ev->Get()->StepId); + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " HandleReply TEvOperationPlan" + << ", step: " << step + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + if (!txState) { + return false; + } + + Y_VERIFY(txState->TxType == TTxState::TxAlterFileStore); + TPathId pathId = txState->TargetPathId; + + auto fs = context.SS->FileStoreInfos.at(pathId); + Y_VERIFY_S(fs, "FileStore info is null. PathId: " << pathId); + + TPathElement::TPtr path = context.SS->PathsById.at(pathId); + path->PathState = TPathElement::EPathState::EPathStateNoChanges; + path->StepCreated = step; + + NIceDb::TNiceDb db(context.Txc.DB); + context.SS->PersistCreateStep(db, pathId, step); + + fs->FinishAlter(); + + context.SS->PersistFileStoreInfo(db, pathId, fs); + context.SS->PersistRemoveFileStoreAlter(db, pathId); + + context.SS->ClearDescribePathCaches(path); + context.OnComplete.PublishToSchemeBoard(OperationId, pathId); + + context.OnComplete.DoneOperation(OperationId); + return false; + } + + bool ProgressState(TOperationContext& context) override { + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " ProgressState" + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + Y_VERIFY(txState); + Y_VERIFY(txState->TxType == TTxState::TxAlterFileStore); + + context.OnComplete.ProposeToCoordinator(OperationId, txState->TargetPathId, TStepId(0)); + return false; + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class TAlterFileStore: public TSubOperation { +private: + const TOperationId OperationId; + const TTxTransaction Transaction; + + TTxState::ETxState State = TTxState::Invalid; + +public: + TAlterFileStore(TOperationId id, const TTxTransaction& tx) + : OperationId(id) + , Transaction(tx) + { + } + + TAlterFileStore(TOperationId id, TTxState::ETxState state) + : OperationId(id) + , State(state) + { + SetState(SelectStateFunc(state)); + } + + THolder<TProposeResponse> Propose( + const TString& owner, + TOperationContext& context) override; + + void AbortPropose(TOperationContext&) override { + Y_FAIL("no AbortPropose for TAlterFileStore"); + } + + void AbortUnsafe(TTxId forceDropTxId, TOperationContext& context) override { + LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + "TAlterFileStore AbortUnsafe" + << ", opId: " << OperationId + << ", forceDropId: " << forceDropTxId + << ", at schemeshard: " << context.SS->TabletID()); + + context.OnComplete.DoneOperation(OperationId); + } + + void StateDone(TOperationContext& context) override { + State = NextState(State); + + if (State != TTxState::Invalid) { + SetState(SelectStateFunc(State)); + context.OnComplete.ActivateTx(OperationId); + } + } + +private: + TTxState::ETxState NextState() { return TTxState::CreateParts; - } - - TTxState::ETxState NextState(TTxState::ETxState state) { - switch(state) { - case TTxState::Waiting: + } + + TTxState::ETxState NextState(TTxState::ETxState state) { + switch(state) { + case TTxState::Waiting: case TTxState::CreateParts: return TTxState::ConfigureParts; - case TTxState::ConfigureParts: - return TTxState::Propose; - default: - return TTxState::Invalid; - } - return TTxState::Invalid; - } - - TSubOperationState::TPtr SelectStateFunc(TTxState::ETxState state) { - switch(state) { - case TTxState::Waiting: + case TTxState::ConfigureParts: + return TTxState::Propose; + default: + return TTxState::Invalid; + } + return TTxState::Invalid; + } + + TSubOperationState::TPtr SelectStateFunc(TTxState::ETxState state) { + switch(state) { + case TTxState::Waiting: case TTxState::CreateParts: return MakeHolder<TCreateParts>(OperationId); - case TTxState::ConfigureParts: + case TTxState::ConfigureParts: return MakeHolder<TConfigureParts>(OperationId); - case TTxState::Propose: + case TTxState::Propose: return MakeHolder<TPropose>(OperationId); - default: - return nullptr; - } - } - - TTxState& PrepareChanges( - TOperationId operationId, TPathElement::TPtr item, - TFileStoreInfo::TPtr fs, + default: + return nullptr; + } + } + + TTxState& PrepareChanges( + TOperationId operationId, TPathElement::TPtr item, + TFileStoreInfo::TPtr fs, const TChannelsBindings& partitionChannels, - TOperationContext& context); - - const NKikimrFileStore::TConfig* ParseParams( + TOperationContext& context); + + const NKikimrFileStore::TConfig* ParseParams( const NKikimrSchemeOp::TFileStoreDescription& operation, - TString& errStr); + TString& errStr); bool ProcessChannelProfiles( const TPath& path, @@ -297,96 +297,96 @@ private: TFileStoreInfo::TPtr volume, const TChannelsBindings& channelBindings, TOperationContext& context); -}; - -//////////////////////////////////////////////////////////////////////////////// - -THolder<TProposeResponse> TAlterFileStore::Propose( - const TString& owner, - TOperationContext& context) -{ - Y_UNUSED(owner); - - const auto ssId = context.SS->SelfTabletId(); - - const auto& operation = Transaction.GetAlterFileStore(); - const TString& parentPathStr = Transaction.GetWorkingDir(); - const TString& name = operation.GetName(); - const TPathId pathId = operation.HasPathId() - ? context.SS->MakeLocalId(operation.GetPathId()) - : InvalidPathId; - - LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "TAlterFileStore Propose" - << ", path: " << parentPathStr << "/" << name - << ", pathId: " << pathId - << ", opId: " << OperationId - << ", at schemeshard: " << ssId); - - auto result = MakeHolder<TProposeResponse>( +}; + +//////////////////////////////////////////////////////////////////////////////// + +THolder<TProposeResponse> TAlterFileStore::Propose( + const TString& owner, + TOperationContext& context) +{ + Y_UNUSED(owner); + + const auto ssId = context.SS->SelfTabletId(); + + const auto& operation = Transaction.GetAlterFileStore(); + const TString& parentPathStr = Transaction.GetWorkingDir(); + const TString& name = operation.GetName(); + const TPathId pathId = operation.HasPathId() + ? context.SS->MakeLocalId(operation.GetPathId()) + : InvalidPathId; + + LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + "TAlterFileStore Propose" + << ", path: " << parentPathStr << "/" << name + << ", pathId: " << pathId + << ", opId: " << OperationId + << ", at schemeshard: " << ssId); + + auto result = MakeHolder<TProposeResponse>( NKikimrScheme::StatusAccepted, - ui64(OperationId.GetTxId()), - ui64(ssId)); - - TString errStr; - if (!operation.HasName() && !operation.HasPathId()) { - errStr = "Neither name nor pathId are present in FileStore"; + ui64(OperationId.GetTxId()), + ui64(ssId)); + + TString errStr; + if (!operation.HasName() && !operation.HasPathId()) { + errStr = "Neither name nor pathId are present in FileStore"; result->SetError(NKikimrScheme::StatusInvalidParameter, errStr); - return result; - } - - TPath path = operation.HasPathId() - ? TPath::Init(pathId, context.SS) - : TPath::Resolve(parentPathStr, context.SS).Dive(name); - - { - auto checks = path.Check(); - checks - .NotEmpty() - .NotUnderDomainUpgrade() - .IsAtLocalSchemeShard() - .IsResolved() - .NotDeleted() - .IsFileStore() - .NotUnderOperation() - .IsCommonSensePath(); - - if (!checks) { - TString explain = TStringBuilder() - << "path fail checks" - << ", path: " << path.PathString(); - - auto status = checks.GetStatus(&explain); - result->SetError(status, explain); - return result; - } - } - - Y_VERIFY(path.Base()->IsCreateFinished()); - - auto fs = context.SS->FileStoreInfos.at(path.Base()->PathId); - Y_VERIFY_S(fs, "FileStore info is null. PathId: " << path.Base()->PathId); - - if (fs->AlterConfig) { - result->SetError( + return result; + } + + TPath path = operation.HasPathId() + ? TPath::Init(pathId, context.SS) + : TPath::Resolve(parentPathStr, context.SS).Dive(name); + + { + auto checks = path.Check(); + checks + .NotEmpty() + .NotUnderDomainUpgrade() + .IsAtLocalSchemeShard() + .IsResolved() + .NotDeleted() + .IsFileStore() + .NotUnderOperation() + .IsCommonSensePath(); + + if (!checks) { + TString explain = TStringBuilder() + << "path fail checks" + << ", path: " << path.PathString(); + + auto status = checks.GetStatus(&explain); + result->SetError(status, explain); + return result; + } + } + + Y_VERIFY(path.Base()->IsCreateFinished()); + + auto fs = context.SS->FileStoreInfos.at(path.Base()->PathId); + Y_VERIFY_S(fs, "FileStore info is null. PathId: " << path.Base()->PathId); + + if (fs->AlterConfig) { + result->SetError( NKikimrScheme::StatusMultipleModifications, - "There is another operation in flight"); - return result; - } - - const auto* alterConfig = ParseParams(operation, errStr); - if (!alterConfig) { + "There is another operation in flight"); + return result; + } + + const auto* alterConfig = ParseParams(operation, errStr); + if (!alterConfig) { result->SetError(NKikimrScheme::StatusInvalidParameter, errStr); - return result; - } - + return result; + } + if (alterConfig->HasVersion() && alterConfig->GetVersion() != fs->Version) { - result->SetError( + result->SetError( NKikimrScheme::StatusPreconditionFailed, - "Wrong version in config"); - return result; - } - + "Wrong version in config"); + return result; + } + TChannelsBindings storeChannelsBinding; const auto channelProfilesProcessed = ProcessChannelProfiles( path, @@ -400,23 +400,23 @@ THolder<TProposeResponse> TAlterFileStore::Propose( return result; } - if (!context.SS->CheckApplyIf(Transaction, errStr)) { + if (!context.SS->CheckApplyIf(Transaction, errStr)) { result->SetError(NKikimrScheme::StatusPreconditionFailed, errStr); - return result; - } - - fs->PrepareAlter(*alterConfig); - + return result; + } + + fs->PrepareAlter(*alterConfig); + PrepareChanges(OperationId, path.Base(), fs, storeChannelsBinding, context); - - context.SS->ClearDescribePathCaches(path.Base()); - context.OnComplete.PublishToSchemeBoard(OperationId, path.Base()->PathId); - - State = NextState(); - SetState(SelectStateFunc(State)); - return result; -} - + + context.SS->ClearDescribePathCaches(path.Base()); + context.OnComplete.PublishToSchemeBoard(OperationId, path.Base()->PathId); + + State = NextState(); + SetState(SelectStateFunc(State)); + return result; +} + const NKikimrFileStore::TConfig* TAlterFileStore::ParseParams( const NKikimrSchemeOp::TFileStoreDescription& operation, TString& errStr) @@ -441,50 +441,50 @@ const NKikimrFileStore::TConfig* TAlterFileStore::ParseParams( return &config; } -TTxState& TAlterFileStore::PrepareChanges( - TOperationId operationId, - TPathElement::TPtr item, - TFileStoreInfo::TPtr fs, +TTxState& TAlterFileStore::PrepareChanges( + TOperationId operationId, + TPathElement::TPtr item, + TFileStoreInfo::TPtr fs, const TChannelsBindings& channelBindings, - TOperationContext& context) -{ - NIceDb::TNiceDb db(context.Txc.DB); - - item->LastTxId = operationId.GetTxId(); - item->PathState = TPathElement::EPathState::EPathStateAlter; - - TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxAlterFileStore, item->PathId); + TOperationContext& context) +{ + NIceDb::TNiceDb db(context.Txc.DB); + + item->LastTxId = operationId.GetTxId(); + item->PathState = TPathElement::EPathState::EPathStateAlter; + + TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxAlterFileStore, item->PathId); txState.State = TTxState::CreateParts; - + ApplyChannelBindings( fs, channelBindings, context); - txState.Shards.reserve(1); - { - TShardIdx shardIdx = fs->IndexShardIdx; - TTabletId tabletId = fs->IndexTabletId; - - Y_VERIFY(context.SS->ShardInfos.contains(shardIdx)); - auto& shardInfo = context.SS->ShardInfos[shardIdx]; - Y_VERIFY(shardInfo.TabletID == tabletId); + txState.Shards.reserve(1); + { + TShardIdx shardIdx = fs->IndexShardIdx; + TTabletId tabletId = fs->IndexTabletId; + + Y_VERIFY(context.SS->ShardInfos.contains(shardIdx)); + auto& shardInfo = context.SS->ShardInfos[shardIdx]; + Y_VERIFY(shardInfo.TabletID == tabletId); txState.Shards.emplace_back(shardIdx, ETabletType::FileStore, TTxState::CreateParts); - shardInfo.CurrentTxId = operationId.GetTxId(); - context.SS->PersistShardTx(db, shardIdx, operationId.GetTxId()); - } - - LOG_DEBUG(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "AlterFileStore txid# %" PRIu64 ", AlterVersion %" PRIu64, - operationId.GetTxId(), fs->AlterVersion); - - context.SS->PersistAddFileStoreAlter(db, item->PathId, fs); + shardInfo.CurrentTxId = operationId.GetTxId(); + context.SS->PersistShardTx(db, shardIdx, operationId.GetTxId()); + } + + LOG_DEBUG(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + "AlterFileStore txid# %" PRIu64 ", AlterVersion %" PRIu64, + operationId.GetTxId(), fs->AlterVersion); + + context.SS->PersistAddFileStoreAlter(db, item->PathId, fs); context.SS->PersistTxState(db, operationId); - - context.OnComplete.ActivateTx(operationId); - return txState; -} - + + context.OnComplete.ActivateTx(operationId); + return txState; +} + bool TAlterFileStore::ProcessChannelProfiles( const TPath& path, const NKikimrFileStore::TConfig& config, @@ -492,7 +492,7 @@ bool TAlterFileStore::ProcessChannelProfiles( TOperationContext& context, TProposeResponse& result, TChannelsBindings& storeChannelsBinding) -{ +{ const auto& alterEcps = alterConfig.GetExplicitChannelProfiles(); if (alterEcps.size()) { @@ -528,29 +528,29 @@ bool TAlterFileStore::ProcessChannelProfiles( } } } - } - + } + const auto& ecps = alterEcps.empty() ? config.GetExplicitChannelProfiles() : alterEcps; TVector<TStringBuf> partitionPoolKinds(Reserve(ecps.size())); for (const auto& ecp : ecps) { partitionPoolKinds.push_back(ecp.GetPoolKind()); - } - + } + const auto storeChannelsResolved = context.SS->ResolveChannelsByPoolKinds( partitionPoolKinds, path.DomainId(), storeChannelsBinding); - + if (!storeChannelsResolved) { result.SetError(NKikimrScheme::StatusInvalidParameter, "Unable to construct channel binding for filestore with the storage pool"); return false; - } - + } + context.SS->SetNfsChannelsParams(ecps, storeChannelsBinding); return true; -} - +} + void TAlterFileStore::ApplyChannelBindings( TFileStoreInfo::TPtr fs, const TChannelsBindings& channelBindings, @@ -564,21 +564,21 @@ void TAlterFileStore::ApplyChannelBindings( } } -} // namespace - -namespace NKikimr { +} // namespace + +namespace NKikimr { namespace NSchemeShard { - -//////////////////////////////////////////////////////////////////////////////// - -ISubOperationBase::TPtr CreateAlterFileStore(TOperationId id, const TTxTransaction& tx) { - return new TAlterFileStore(id, tx); -} - -ISubOperationBase::TPtr CreateAlterFileStore(TOperationId id, TTxState::ETxState state) { - Y_VERIFY(state != TTxState::Invalid); - return new TAlterFileStore(id, state); -} - + +//////////////////////////////////////////////////////////////////////////////// + +ISubOperationBase::TPtr CreateAlterFileStore(TOperationId id, const TTxTransaction& tx) { + return new TAlterFileStore(id, tx); +} + +ISubOperationBase::TPtr CreateAlterFileStore(TOperationId id, TTxState::ETxState state) { + Y_VERIFY(state != TTxState::Invalid); + return new TAlterFileStore(id, state); +} + } // namespace NSchemeShard -} // namespace NKikimr +} // namespace NKikimr diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp index b1a28412bc..6d908a55e8 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp @@ -1,393 +1,393 @@ -#include "schemeshard__operation_part.h" -#include "schemeshard__operation_common.h" -#include "schemeshard_impl.h" - +#include "schemeshard__operation_part.h" +#include "schemeshard__operation_common.h" +#include "schemeshard_impl.h" + #include <ydb/core/base/subdomain.h> #include <ydb/core/mind/hive/hive.h> - -namespace { - -using namespace NKikimr; + +namespace { + +using namespace NKikimr; using namespace NSchemeShard; - -//////////////////////////////////////////////////////////////////////////////// - -class TConfigureParts: public TSubOperationState { -private: - const TOperationId OperationId; - + +//////////////////////////////////////////////////////////////////////////////// + +class TConfigureParts: public TSubOperationState { +private: + const TOperationId OperationId; + TString DebugHint() const override { - return TStringBuilder() - << "TCreateFileStore::TConfigureParts" - << " operationId#" << OperationId; - } - -public: - TConfigureParts(TOperationId id) - : OperationId(id) - { - IgnoreMessages(DebugHint(), { - TEvHive::TEvCreateTabletReply::EventType - }); - } - - bool HandleReply( - TEvFileStore::TEvUpdateConfigResponse::TPtr& ev, - TOperationContext& context) override - { - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " HandleReply TEvUpdateConfigResponse" - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - Y_VERIFY(txState); - Y_VERIFY(txState->TxType == TTxState::TxCreateFileStore); - Y_VERIFY(txState->State == TTxState::ConfigureParts); - - auto tabletId = TTabletId(ev->Get()->Record.GetOrigin()); - auto status = ev->Get()->Record.GetStatus(); - - // Schemeshard never sends invalid or outdated configs - Y_VERIFY_S(status == NKikimrFileStore::OK || status == NKikimrFileStore::ERROR_UPDATE_IN_PROGRESS, - "Unexpected error in UpdateConfigResponse" - << ", status: " << NKikimrFileStore::EStatus_Name(status) - << ", tx: " << OperationId - << ", tablet: " << tabletId - << ", at schemeshard: " << ssId); - - if (status == NKikimrFileStore::ERROR_UPDATE_IN_PROGRESS) { - LOG_ERROR_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " Reconfiguration is in progress. We'll try to finish it later." - << " tx: " << OperationId - << " tablet: " << tabletId); - return false; - } - + return TStringBuilder() + << "TCreateFileStore::TConfigureParts" + << " operationId#" << OperationId; + } + +public: + TConfigureParts(TOperationId id) + : OperationId(id) + { + IgnoreMessages(DebugHint(), { + TEvHive::TEvCreateTabletReply::EventType + }); + } + + bool HandleReply( + TEvFileStore::TEvUpdateConfigResponse::TPtr& ev, + TOperationContext& context) override + { + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " HandleReply TEvUpdateConfigResponse" + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + Y_VERIFY(txState); + Y_VERIFY(txState->TxType == TTxState::TxCreateFileStore); + Y_VERIFY(txState->State == TTxState::ConfigureParts); + + auto tabletId = TTabletId(ev->Get()->Record.GetOrigin()); + auto status = ev->Get()->Record.GetStatus(); + + // Schemeshard never sends invalid or outdated configs + Y_VERIFY_S(status == NKikimrFileStore::OK || status == NKikimrFileStore::ERROR_UPDATE_IN_PROGRESS, + "Unexpected error in UpdateConfigResponse" + << ", status: " << NKikimrFileStore::EStatus_Name(status) + << ", tx: " << OperationId + << ", tablet: " << tabletId + << ", at schemeshard: " << ssId); + + if (status == NKikimrFileStore::ERROR_UPDATE_IN_PROGRESS) { + LOG_ERROR_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " Reconfiguration is in progress. We'll try to finish it later." + << " tx: " << OperationId + << " tablet: " << tabletId); + return false; + } + auto idx = context.SS->MustGetShardIdx(tabletId); - txState->ShardsInProgress.erase(idx); - - context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); - - if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); - context.SS->ChangeTxState(db, OperationId, TTxState::Propose); - context.OnComplete.ActivateTx(OperationId); - return true; - } - - return false; - } - - bool ProgressState(TOperationContext& context) override { - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " ProgressState" - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - Y_VERIFY(txState); - Y_VERIFY(txState->TxType == TTxState::TxCreateFileStore); - Y_VERIFY(!txState->Shards.empty()); - - txState->ClearShardsInProgress(); - - auto fs = context.SS->FileStoreInfos[txState->TargetPathId]; - Y_VERIFY_S(fs, "FileStore info is null. PathId: " << txState->TargetPathId); - - Y_VERIFY(txState->Shards.size() == 1); - for (const auto& shard: txState->Shards) { - Y_VERIFY(shard.TabletType == ETabletType::FileStore); - auto shardIdx = shard.Idx; - auto tabletId = context.SS->ShardInfos[shardIdx].TabletID; - - fs->IndexShardIdx = shardIdx; - fs->IndexTabletId = tabletId; - - TAutoPtr<TEvFileStore::TEvUpdateConfig> event(new TEvFileStore::TEvUpdateConfig()); - event->Record.SetTxId(ui64(OperationId.GetTxId())); - event->Record.MutableConfig()->CopyFrom(fs->Config); - event->Record.MutableConfig()->SetVersion(fs->Version); - - context.OnComplete.BindMsgToPipe(OperationId, tabletId, shardIdx, event.Release()); - - // Wait for results from this shard - txState->ShardsInProgress.insert(shardIdx); - } - - return false; - } -}; - -//////////////////////////////////////////////////////////////////////////////// - -class TPropose: public TSubOperationState { -private: - const TOperationId OperationId; - + txState->ShardsInProgress.erase(idx); + + context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); + + if (txState->ShardsInProgress.empty()) { + NIceDb::TNiceDb db(context.Txc.DB); + context.SS->ChangeTxState(db, OperationId, TTxState::Propose); + context.OnComplete.ActivateTx(OperationId); + return true; + } + + return false; + } + + bool ProgressState(TOperationContext& context) override { + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " ProgressState" + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + Y_VERIFY(txState); + Y_VERIFY(txState->TxType == TTxState::TxCreateFileStore); + Y_VERIFY(!txState->Shards.empty()); + + txState->ClearShardsInProgress(); + + auto fs = context.SS->FileStoreInfos[txState->TargetPathId]; + Y_VERIFY_S(fs, "FileStore info is null. PathId: " << txState->TargetPathId); + + Y_VERIFY(txState->Shards.size() == 1); + for (const auto& shard: txState->Shards) { + Y_VERIFY(shard.TabletType == ETabletType::FileStore); + auto shardIdx = shard.Idx; + auto tabletId = context.SS->ShardInfos[shardIdx].TabletID; + + fs->IndexShardIdx = shardIdx; + fs->IndexTabletId = tabletId; + + TAutoPtr<TEvFileStore::TEvUpdateConfig> event(new TEvFileStore::TEvUpdateConfig()); + event->Record.SetTxId(ui64(OperationId.GetTxId())); + event->Record.MutableConfig()->CopyFrom(fs->Config); + event->Record.MutableConfig()->SetVersion(fs->Version); + + context.OnComplete.BindMsgToPipe(OperationId, tabletId, shardIdx, event.Release()); + + // Wait for results from this shard + txState->ShardsInProgress.insert(shardIdx); + } + + return false; + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class TPropose: public TSubOperationState { +private: + const TOperationId OperationId; + TString DebugHint() const override { - return TStringBuilder() - << "TCreateFileStore::TPropose" - << " operationId#" << OperationId; - } - -public: - TPropose(TOperationId id) - : OperationId(id) - { - IgnoreMessages(DebugHint(), { - TEvHive::TEvCreateTabletReply::EventType, - TEvFileStore::TEvUpdateConfigResponse::EventType - }); - } - - bool HandleReply(TEvPrivate::TEvOperationPlan::TPtr& ev, TOperationContext& context) override { - const auto step = TStepId(ev->Get()->StepId); - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " HandleReply TEvOperationPlan" - << ", step: " << step - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - if (!txState) { - return false; - } - - Y_VERIFY(txState->TxType == TTxState::TxCreateFileStore); - TPathId pathId = txState->TargetPathId; - - TPathElement::TPtr path = context.SS->PathsById.at(pathId); - path->StepCreated = step; - - NIceDb::TNiceDb db(context.Txc.DB); - context.SS->PersistCreateStep(db, pathId, step); - - auto parentDir = context.SS->PathsById.at(path->ParentPathId); - ++parentDir->DirAlterVersion; - context.SS->PersistPathDirAlterVersion(db, parentDir); - context.SS->ClearDescribePathCaches(parentDir); - context.OnComplete.PublishToSchemeBoard(OperationId, parentDir->PathId); - - context.SS->ClearDescribePathCaches(path); - context.OnComplete.PublishToSchemeBoard(OperationId, pathId); - - context.SS->ChangeTxState(db, OperationId, TTxState::Done); - return true; - } - - bool ProgressState(TOperationContext& context) override { - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " ProgressState" - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - Y_VERIFY(txState); - Y_VERIFY(txState->TxType == TTxState::TxCreateFileStore); - - context.OnComplete.ProposeToCoordinator(OperationId, txState->TargetPathId, TStepId(0)); - return false; - } -}; - -//////////////////////////////////////////////////////////////////////////////// - -class TCreateFileStore: public TSubOperation { -private: - const TOperationId OperationId; - const TTxTransaction Transaction; - - TTxState::ETxState State = TTxState::Invalid; - -public: - TCreateFileStore(TOperationId id, const TTxTransaction& tx) - : OperationId(id) - , Transaction(tx) - { - } - - TCreateFileStore(TOperationId id, TTxState::ETxState state) - : OperationId(id) - , State(state) - { - SetState(SelectStateFunc(state)); - } - - THolder<TProposeResponse> Propose( - const TString& owner, - TOperationContext& context) override; - - void AbortPropose(TOperationContext&) override { - Y_FAIL("no AbortPropose for TCreateFileStore"); - } - - void AbortUnsafe(TTxId forceDropTxId, TOperationContext& context) override { - LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "TCreateFileStore AbortUnsafe" - << ", opId: " << OperationId - << ", forceDropId: " << forceDropTxId - << ", at schemeshard: " << context.SS->TabletID()); - - context.OnComplete.DoneOperation(OperationId); - } - - void StateDone(TOperationContext& context) override { - State = NextState(State); - - if (State != TTxState::Invalid) { - SetState(SelectStateFunc(State)); - context.OnComplete.ActivateTx(OperationId); - } - } - -private: - TTxState::ETxState NextState() { - return TTxState::CreateParts; - } - - TTxState::ETxState NextState(TTxState::ETxState state) { - switch(state) { - case TTxState::Waiting: - case TTxState::CreateParts: - return TTxState::ConfigureParts; - case TTxState::ConfigureParts: - return TTxState::Propose; - case TTxState::Propose: - return TTxState::Done; - default: - return TTxState::Invalid; - } - return TTxState::Invalid; - } - - TSubOperationState::TPtr SelectStateFunc(TTxState::ETxState state) { - switch(state) { - case TTxState::Waiting: - case TTxState::CreateParts: - return MakeHolder<TCreateParts>(OperationId); - case TTxState::ConfigureParts: - return MakeHolder<TConfigureParts>(OperationId); - case TTxState::Propose: - return MakeHolder<TPropose>(OperationId); - case TTxState::Done: - return MakeHolder<TDone>(OperationId); - default: - return nullptr; - } - } - - TFileStoreInfo::TPtr CreateFileStoreInfo( + return TStringBuilder() + << "TCreateFileStore::TPropose" + << " operationId#" << OperationId; + } + +public: + TPropose(TOperationId id) + : OperationId(id) + { + IgnoreMessages(DebugHint(), { + TEvHive::TEvCreateTabletReply::EventType, + TEvFileStore::TEvUpdateConfigResponse::EventType + }); + } + + bool HandleReply(TEvPrivate::TEvOperationPlan::TPtr& ev, TOperationContext& context) override { + const auto step = TStepId(ev->Get()->StepId); + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " HandleReply TEvOperationPlan" + << ", step: " << step + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + if (!txState) { + return false; + } + + Y_VERIFY(txState->TxType == TTxState::TxCreateFileStore); + TPathId pathId = txState->TargetPathId; + + TPathElement::TPtr path = context.SS->PathsById.at(pathId); + path->StepCreated = step; + + NIceDb::TNiceDb db(context.Txc.DB); + context.SS->PersistCreateStep(db, pathId, step); + + auto parentDir = context.SS->PathsById.at(path->ParentPathId); + ++parentDir->DirAlterVersion; + context.SS->PersistPathDirAlterVersion(db, parentDir); + context.SS->ClearDescribePathCaches(parentDir); + context.OnComplete.PublishToSchemeBoard(OperationId, parentDir->PathId); + + context.SS->ClearDescribePathCaches(path); + context.OnComplete.PublishToSchemeBoard(OperationId, pathId); + + context.SS->ChangeTxState(db, OperationId, TTxState::Done); + return true; + } + + bool ProgressState(TOperationContext& context) override { + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " ProgressState" + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + Y_VERIFY(txState); + Y_VERIFY(txState->TxType == TTxState::TxCreateFileStore); + + context.OnComplete.ProposeToCoordinator(OperationId, txState->TargetPathId, TStepId(0)); + return false; + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class TCreateFileStore: public TSubOperation { +private: + const TOperationId OperationId; + const TTxTransaction Transaction; + + TTxState::ETxState State = TTxState::Invalid; + +public: + TCreateFileStore(TOperationId id, const TTxTransaction& tx) + : OperationId(id) + , Transaction(tx) + { + } + + TCreateFileStore(TOperationId id, TTxState::ETxState state) + : OperationId(id) + , State(state) + { + SetState(SelectStateFunc(state)); + } + + THolder<TProposeResponse> Propose( + const TString& owner, + TOperationContext& context) override; + + void AbortPropose(TOperationContext&) override { + Y_FAIL("no AbortPropose for TCreateFileStore"); + } + + void AbortUnsafe(TTxId forceDropTxId, TOperationContext& context) override { + LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + "TCreateFileStore AbortUnsafe" + << ", opId: " << OperationId + << ", forceDropId: " << forceDropTxId + << ", at schemeshard: " << context.SS->TabletID()); + + context.OnComplete.DoneOperation(OperationId); + } + + void StateDone(TOperationContext& context) override { + State = NextState(State); + + if (State != TTxState::Invalid) { + SetState(SelectStateFunc(State)); + context.OnComplete.ActivateTx(OperationId); + } + } + +private: + TTxState::ETxState NextState() { + return TTxState::CreateParts; + } + + TTxState::ETxState NextState(TTxState::ETxState state) { + switch(state) { + case TTxState::Waiting: + case TTxState::CreateParts: + return TTxState::ConfigureParts; + case TTxState::ConfigureParts: + return TTxState::Propose; + case TTxState::Propose: + return TTxState::Done; + default: + return TTxState::Invalid; + } + return TTxState::Invalid; + } + + TSubOperationState::TPtr SelectStateFunc(TTxState::ETxState state) { + switch(state) { + case TTxState::Waiting: + case TTxState::CreateParts: + return MakeHolder<TCreateParts>(OperationId); + case TTxState::ConfigureParts: + return MakeHolder<TConfigureParts>(OperationId); + case TTxState::Propose: + return MakeHolder<TPropose>(OperationId); + case TTxState::Done: + return MakeHolder<TDone>(OperationId); + default: + return nullptr; + } + } + + TFileStoreInfo::TPtr CreateFileStoreInfo( const NKikimrSchemeOp::TFileStoreDescription& op, TEvSchemeShard::EStatus& status, - TString& errStr); - - TTxState& PrepareChanges( - TOperationId operationId, - TPathElement::TPtr parentDir, - TPathElement::TPtr fsPath, - TFileStoreInfo::TPtr fs, - const TString& acl, - const TChannelsBindings& tabletChannels, - TOperationContext& context); -}; - -//////////////////////////////////////////////////////////////////////////////// - -THolder<TProposeResponse> TCreateFileStore::Propose( - const TString& owner, - TOperationContext& context) -{ - const auto ssId = context.SS->SelfTabletId(); - + TString& errStr); + + TTxState& PrepareChanges( + TOperationId operationId, + TPathElement::TPtr parentDir, + TPathElement::TPtr fsPath, + TFileStoreInfo::TPtr fs, + const TString& acl, + const TChannelsBindings& tabletChannels, + TOperationContext& context); +}; + +//////////////////////////////////////////////////////////////////////////////// + +THolder<TProposeResponse> TCreateFileStore::Propose( + const TString& owner, + TOperationContext& context) +{ + const auto ssId = context.SS->SelfTabletId(); + const auto acceptExisted = !Transaction.GetFailOnExist(); - const auto& operation = Transaction.GetCreateFileStore(); - const TString& parentPathStr = Transaction.GetWorkingDir(); - const TString& name = Transaction.GetCreateFileStore().GetName(); - const ui64 shardsToCreate = 1; - - LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "TCreateFileStore Propose" - << ", path: " << parentPathStr << "/" << name - << ", opId: " << OperationId - << ", at schemeshard: " << ssId); - + const auto& operation = Transaction.GetCreateFileStore(); + const TString& parentPathStr = Transaction.GetWorkingDir(); + const TString& name = Transaction.GetCreateFileStore().GetName(); + const ui64 shardsToCreate = 1; + + LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + "TCreateFileStore Propose" + << ", path: " << parentPathStr << "/" << name + << ", opId: " << OperationId + << ", at schemeshard: " << ssId); + auto status = NKikimrScheme::StatusAccepted; - auto result = MakeHolder<TProposeResponse>( - status, - ui64(OperationId.GetTxId()), - ui64(ssId)); - + auto result = MakeHolder<TProposeResponse>( + status, + ui64(OperationId.GetTxId()), + ui64(ssId)); + auto parentPath = NSchemeShard::TPath::Resolve(parentPathStr, context.SS); - { - auto checks = parentPath.Check(); - checks - .NotUnderDomainUpgrade() - .IsAtLocalSchemeShard() - .IsResolved() - .NotDeleted() - .NotUnderDeleting() - .IsCommonSensePath() - .IsLikeDirectory(); - - if (!checks) { - TString explain = TStringBuilder() - << "parent path fail checks" - << ", path: " << parentPath.PathString(); - - auto status = checks.GetStatus(&explain); - result->SetError(status, explain); - return result; - } - } - - const TString acl = Transaction.GetModifyACL().GetDiffACL(); - - auto dstPath = parentPath.Child(name); - { - auto checks = dstPath.Check(); - checks.IsAtLocalSchemeShard(); - if (dstPath.IsResolved()) { - checks - .IsResolved() - .NotUnderDeleting() - .FailOnExist(TPathElement::EPathType::EPathTypeFileStore, acceptExisted); - } else { - checks - .NotEmpty() - .NotResolved(); - } - - if (checks) { - checks - .IsValidLeafName() - .DepthLimit() - .PathsLimit() - .DirChildrenLimit() - .ShardsLimit(shardsToCreate) - .PathShardsLimit(shardsToCreate) - .IsValidACL(acl); - } - - if (!checks) { - TString explain = TStringBuilder() - << "dst path fail checks" - << ", path: " << dstPath.PathString(); - - auto status = checks.GetStatus(&explain); - result->SetError(status, explain); - if (dstPath.IsResolved()) { - result->SetPathCreateTxId(ui64(dstPath.Base()->CreateTxId)); - result->SetPathId(dstPath.Base()->PathId.LocalPathId); - } - return result; - } - } - + { + auto checks = parentPath.Check(); + checks + .NotUnderDomainUpgrade() + .IsAtLocalSchemeShard() + .IsResolved() + .NotDeleted() + .NotUnderDeleting() + .IsCommonSensePath() + .IsLikeDirectory(); + + if (!checks) { + TString explain = TStringBuilder() + << "parent path fail checks" + << ", path: " << parentPath.PathString(); + + auto status = checks.GetStatus(&explain); + result->SetError(status, explain); + return result; + } + } + + const TString acl = Transaction.GetModifyACL().GetDiffACL(); + + auto dstPath = parentPath.Child(name); + { + auto checks = dstPath.Check(); + checks.IsAtLocalSchemeShard(); + if (dstPath.IsResolved()) { + checks + .IsResolved() + .NotUnderDeleting() + .FailOnExist(TPathElement::EPathType::EPathTypeFileStore, acceptExisted); + } else { + checks + .NotEmpty() + .NotResolved(); + } + + if (checks) { + checks + .IsValidLeafName() + .DepthLimit() + .PathsLimit() + .DirChildrenLimit() + .ShardsLimit(shardsToCreate) + .PathShardsLimit(shardsToCreate) + .IsValidACL(acl); + } + + if (!checks) { + TString explain = TStringBuilder() + << "dst path fail checks" + << ", path: " << dstPath.PathString(); + + auto status = checks.GetStatus(&explain); + result->SetError(status, explain); + if (dstPath.IsResolved()) { + result->SetPathCreateTxId(ui64(dstPath.Base()->CreateTxId)); + result->SetPathId(dstPath.Base()->PathId.LocalPathId); + } + return result; + } + } + const auto& ecps = operation.GetConfig().GetExplicitChannelProfiles(); if (ecps.empty() || ui32(ecps.size()) > NHive::MAX_TABLET_CHANNELS) { auto errStr = Sprintf("Wrong number of channels %u , should be [1 .. %lu]", @@ -412,154 +412,154 @@ THolder<TProposeResponse> TCreateFileStore::Propose( if (!storeChannelsResolved) { result->SetError(NKikimrScheme::StatusInvalidParameter, "Unable to construct channel binding for filestore with the storage pool"); - return result; - } - + return result; + } + context.SS->SetNfsChannelsParams(ecps, storeChannelBindings); - TString errStr; - if (!context.SS->CheckApplyIf(Transaction, errStr)) { + TString errStr; + if (!context.SS->CheckApplyIf(Transaction, errStr)) { result->SetError(NKikimrScheme::StatusPreconditionFailed, errStr); - return result; - } - - auto fs = CreateFileStoreInfo(operation, status, errStr); - if (!fs) { - result->SetError(status, errStr); - return result; - } - - dstPath.MaterializeLeaf(owner); - result->SetPathId(dstPath.Base()->PathId.LocalPathId); - - context.SS->TabletCounters->Simple()[COUNTER_FILESTORE_COUNT].Add(1); - - const TTxState& txState = PrepareChanges( - OperationId, - parentPath.Base(), - dstPath.Base(), - fs, - acl, + return result; + } + + auto fs = CreateFileStoreInfo(operation, status, errStr); + if (!fs) { + result->SetError(status, errStr); + return result; + } + + dstPath.MaterializeLeaf(owner); + result->SetPathId(dstPath.Base()->PathId.LocalPathId); + + context.SS->TabletCounters->Simple()[COUNTER_FILESTORE_COUNT].Add(1); + + const TTxState& txState = PrepareChanges( + OperationId, + parentPath.Base(), + dstPath.Base(), + fs, + acl, storeChannelBindings, - context); - - NIceDb::TNiceDb db(context.Txc.DB); - ++parentPath.Base()->DirAlterVersion; - context.SS->PersistPathDirAlterVersion(db, parentPath.Base()); - context.SS->ClearDescribePathCaches(parentPath.Base()); - context.OnComplete.PublishToSchemeBoard(OperationId, parentPath.Base()->PathId); - - context.SS->ClearDescribePathCaches(dstPath.Base()); - context.OnComplete.PublishToSchemeBoard(OperationId, dstPath.Base()->PathId); - - dstPath.DomainInfo()->IncPathsInside(); - dstPath.DomainInfo()->AddInternalShards(txState); - dstPath.Base()->IncShardsInside(shardsToCreate); - parentPath.Base()->IncAliveChildren(); - - State = NextState(); - SetState(SelectStateFunc(State)); - return result; -} - -TFileStoreInfo::TPtr TCreateFileStore::CreateFileStoreInfo( + context); + + NIceDb::TNiceDb db(context.Txc.DB); + ++parentPath.Base()->DirAlterVersion; + context.SS->PersistPathDirAlterVersion(db, parentPath.Base()); + context.SS->ClearDescribePathCaches(parentPath.Base()); + context.OnComplete.PublishToSchemeBoard(OperationId, parentPath.Base()->PathId); + + context.SS->ClearDescribePathCaches(dstPath.Base()); + context.OnComplete.PublishToSchemeBoard(OperationId, dstPath.Base()->PathId); + + dstPath.DomainInfo()->IncPathsInside(); + dstPath.DomainInfo()->AddInternalShards(txState); + dstPath.Base()->IncShardsInside(shardsToCreate); + parentPath.Base()->IncAliveChildren(); + + State = NextState(); + SetState(SelectStateFunc(State)); + return result; +} + +TFileStoreInfo::TPtr TCreateFileStore::CreateFileStoreInfo( const NKikimrSchemeOp::TFileStoreDescription& op, TEvSchemeShard::EStatus& status, - TString& errStr) -{ - TFileStoreInfo::TPtr fs = new TFileStoreInfo(); - - const auto& config = op.GetConfig(); - if (!config.HasBlockSize()) { + TString& errStr) +{ + TFileStoreInfo::TPtr fs = new TFileStoreInfo(); + + const auto& config = op.GetConfig(); + if (!config.HasBlockSize()) { status = NKikimrScheme::StatusSchemeError; - errStr = "Block size is required"; - return nullptr; - } - - if (config.HasVersion()) { + errStr = "Block size is required"; + return nullptr; + } + + if (config.HasVersion()) { status = NKikimrScheme::StatusSchemeError; - errStr = "Setting version is not allowed"; - return nullptr; - } - - fs->Version = 1; - fs->Config.CopyFrom(op.GetConfig()); - - return fs; -} - -TTxState& TCreateFileStore::PrepareChanges( - TOperationId operationId, - TPathElement::TPtr parentDir, - TPathElement::TPtr fsPath, - TFileStoreInfo::TPtr fs, - const TString& acl, - const TChannelsBindings& tabletChannels, - TOperationContext& context) -{ - NIceDb::TNiceDb db(context.Txc.DB); - - fsPath->CreateTxId = operationId.GetTxId(); - fsPath->LastTxId = operationId.GetTxId(); - fsPath->PathState = TPathElement::EPathState::EPathStateCreate; - fsPath->PathType = TPathElement::EPathType::EPathTypeFileStore; - TPathId pathId = fsPath->PathId; - - TTxState& txState = context.SS->CreateTx(operationId, TTxState::TxCreateFileStore, pathId); - + errStr = "Setting version is not allowed"; + return nullptr; + } + + fs->Version = 1; + fs->Config.CopyFrom(op.GetConfig()); + + return fs; +} + +TTxState& TCreateFileStore::PrepareChanges( + TOperationId operationId, + TPathElement::TPtr parentDir, + TPathElement::TPtr fsPath, + TFileStoreInfo::TPtr fs, + const TString& acl, + const TChannelsBindings& tabletChannels, + TOperationContext& context) +{ + NIceDb::TNiceDb db(context.Txc.DB); + + fsPath->CreateTxId = operationId.GetTxId(); + fsPath->LastTxId = operationId.GetTxId(); + fsPath->PathState = TPathElement::EPathState::EPathStateCreate; + fsPath->PathType = TPathElement::EPathType::EPathTypeFileStore; + TPathId pathId = fsPath->PathId; + + TTxState& txState = context.SS->CreateTx(operationId, TTxState::TxCreateFileStore, pathId); + auto shardIdx = context.SS->RegisterShardInfo( TShardInfo::FileStoreInfo(operationId.GetTxId(), pathId) .WithBindedChannels(tabletChannels)); context.SS->TabletCounters->Simple()[COUNTER_FILESTORE_SHARD_COUNT].Add(1); - txState.Shards.emplace_back(shardIdx, ETabletType::FileStore, TTxState::CreateParts); - fs->IndexShardIdx = shardIdx; - - if (parentDir->HasActiveChanges()) { - TTxId parentTxId = parentDir->PlannedToCreate() ? parentDir->CreateTxId : parentDir->LastTxId; - context.OnComplete.Dependence(parentTxId, operationId.GetTxId()); - } - - context.SS->ChangeTxState(db, operationId, TTxState::CreateParts); - context.OnComplete.ActivateTx(operationId); - + txState.Shards.emplace_back(shardIdx, ETabletType::FileStore, TTxState::CreateParts); + fs->IndexShardIdx = shardIdx; + + if (parentDir->HasActiveChanges()) { + TTxId parentTxId = parentDir->PlannedToCreate() ? parentDir->CreateTxId : parentDir->LastTxId; + context.OnComplete.Dependence(parentTxId, operationId.GetTxId()); + } + + context.SS->ChangeTxState(db, operationId, TTxState::CreateParts); + context.OnComplete.ActivateTx(operationId); + context.SS->PersistPath(db, fsPath->PathId); - if (!acl.empty()) { - fsPath->ApplyACL(acl); - context.SS->PersistACL(db, fsPath); - } - - context.SS->FileStoreInfos[pathId] = fs; - context.SS->PersistFileStoreInfo(db, pathId, fs); + if (!acl.empty()) { + fsPath->ApplyACL(acl); + context.SS->PersistACL(db, fsPath); + } + + context.SS->FileStoreInfos[pathId] = fs; + context.SS->PersistFileStoreInfo(db, pathId, fs); context.SS->IncrementPathDbRefCount(pathId); - + context.SS->PersistTxState(db, operationId); - context.SS->PersistUpdateNextPathId(db); - context.SS->PersistUpdateNextShardIdx(db); - - for (const auto& shard: txState.Shards) { - Y_VERIFY(shard.Operation == TTxState::CreateParts); - context.SS->PersistChannelsBinding(db, shard.Idx, context.SS->ShardInfos[shard.Idx].BindedChannels); - context.SS->PersistShardMapping(db, shard.Idx, InvalidTabletId, pathId, operationId.GetTxId(), shard.TabletType); - } - - return txState; -} - -} // namespace - -namespace NKikimr { + context.SS->PersistUpdateNextPathId(db); + context.SS->PersistUpdateNextShardIdx(db); + + for (const auto& shard: txState.Shards) { + Y_VERIFY(shard.Operation == TTxState::CreateParts); + context.SS->PersistChannelsBinding(db, shard.Idx, context.SS->ShardInfos[shard.Idx].BindedChannels); + context.SS->PersistShardMapping(db, shard.Idx, InvalidTabletId, pathId, operationId.GetTxId(), shard.TabletType); + } + + return txState; +} + +} // namespace + +namespace NKikimr { namespace NSchemeShard { - -//////////////////////////////////////////////////////////////////////////////// - -ISubOperationBase::TPtr CreateNewFileStore(TOperationId id, const TTxTransaction& tx) { - return new TCreateFileStore(id, tx); -} - -ISubOperationBase::TPtr CreateNewFileStore(TOperationId id, TTxState::ETxState state) { - Y_VERIFY(state != TTxState::Invalid); - return new TCreateFileStore(id, state); -} - + +//////////////////////////////////////////////////////////////////////////////// + +ISubOperationBase::TPtr CreateNewFileStore(TOperationId id, const TTxTransaction& tx) { + return new TCreateFileStore(id, tx); +} + +ISubOperationBase::TPtr CreateNewFileStore(TOperationId id, TTxState::ETxState state) { + Y_VERIFY(state != TTxState::Invalid); + return new TCreateFileStore(id, state); +} + } // namespace NSchemeShard -} // namespace NKikimr +} // namespace NKikimr diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_fs.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_fs.cpp index 97c62aa135..4ba51deb84 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_fs.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_fs.cpp @@ -1,105 +1,105 @@ -#include "schemeshard__operation_part.h" -#include "schemeshard__operation_common.h" -#include "schemeshard_impl.h" - +#include "schemeshard__operation_part.h" +#include "schemeshard__operation_common.h" +#include "schemeshard_impl.h" + #include <ydb/core/base/subdomain.h> #include <ydb/core/mind/hive/hive.h> - -namespace { - -using namespace NKikimr; + +namespace { + +using namespace NKikimr; using namespace NSchemeShard; - -//////////////////////////////////////////////////////////////////////////////// - -class TDeleteParts: public TSubOperationState { -private: - const TOperationId OperationId; - + +//////////////////////////////////////////////////////////////////////////////// + +class TDeleteParts: public TSubOperationState { +private: + const TOperationId OperationId; + TString DebugHint() const override { - return TStringBuilder() - << "TDropFileStore::TDeleteParts" - << ", operationId: " << OperationId; - } - -public: - TDeleteParts(TOperationId id) - : OperationId(id) - { - IgnoreMessages(DebugHint(), {}); - } - - bool ProgressState(TOperationContext& context) override { - TTabletId ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " ProgressState" - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - Y_VERIFY(txState->TxType == TTxState::TxDropFileStore); - - // Initiate asynchonous deletion of all shards - for (const auto& shard: txState->Shards) { - context.OnComplete.DeleteShard(shard.Idx); - } - - NIceDb::TNiceDb db(context.Txc.DB); - context.SS->ChangeTxState(db, OperationId, TTxState::Propose); - return true; - } -}; - -//////////////////////////////////////////////////////////////////////////////// - -class TPropose: public TSubOperationState { -private: - const TOperationId OperationId; - + return TStringBuilder() + << "TDropFileStore::TDeleteParts" + << ", operationId: " << OperationId; + } + +public: + TDeleteParts(TOperationId id) + : OperationId(id) + { + IgnoreMessages(DebugHint(), {}); + } + + bool ProgressState(TOperationContext& context) override { + TTabletId ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " ProgressState" + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + Y_VERIFY(txState->TxType == TTxState::TxDropFileStore); + + // Initiate asynchonous deletion of all shards + for (const auto& shard: txState->Shards) { + context.OnComplete.DeleteShard(shard.Idx); + } + + NIceDb::TNiceDb db(context.Txc.DB); + context.SS->ChangeTxState(db, OperationId, TTxState::Propose); + return true; + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class TPropose: public TSubOperationState { +private: + const TOperationId OperationId; + TString DebugHint() const override { - return TStringBuilder() - << "TDropFileStore::TPropose" - << ", operationId: " << OperationId; - } - -public: - TPropose(TOperationId id) - : OperationId(id) - { - IgnoreMessages(DebugHint(), {}); - } - - bool HandleReply( - TEvPrivate::TEvOperationPlan::TPtr& ev, - TOperationContext& context) override - { - const auto step = TStepId(ev->Get()->StepId); - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " HandleReply TEvOperationPlan" - << ", step: " << step - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - if (!txState) { - return false; - } - - Y_VERIFY(txState->TxType == TTxState::TxDropFileStore); - TPathId pathId = txState->TargetPathId; - auto path = context.SS->PathsById.at(pathId); - auto parentDir = context.SS->PathsById.at(path->ParentPathId); - - NIceDb::TNiceDb db(context.Txc.DB); - - Y_VERIFY(!path->Dropped()); - path->SetDropped(step, OperationId.GetTxId()); - context.SS->PersistDropStep(db, pathId, step, OperationId); - auto domainInfo = context.SS->ResolveDomainInfo(pathId); - domainInfo->DecPathsInside(); - parentDir->DecAliveChildren(); - + return TStringBuilder() + << "TDropFileStore::TPropose" + << ", operationId: " << OperationId; + } + +public: + TPropose(TOperationId id) + : OperationId(id) + { + IgnoreMessages(DebugHint(), {}); + } + + bool HandleReply( + TEvPrivate::TEvOperationPlan::TPtr& ev, + TOperationContext& context) override + { + const auto step = TStepId(ev->Get()->StepId); + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " HandleReply TEvOperationPlan" + << ", step: " << step + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + if (!txState) { + return false; + } + + Y_VERIFY(txState->TxType == TTxState::TxDropFileStore); + TPathId pathId = txState->TargetPathId; + auto path = context.SS->PathsById.at(pathId); + auto parentDir = context.SS->PathsById.at(path->ParentPathId); + + NIceDb::TNiceDb db(context.Txc.DB); + + Y_VERIFY(!path->Dropped()); + path->SetDropped(step, OperationId.GetTxId()); + context.SS->PersistDropStep(db, pathId, step, OperationId); + auto domainInfo = context.SS->ResolveDomainInfo(pathId); + domainInfo->DecPathsInside(); + parentDir->DecAliveChildren(); + // KIKIMR-13173 // Repeat it here for a waile, delete it from TDeleteParts after // Initiate asynchonous deletion of all shards @@ -112,254 +112,254 @@ public: } context.SS->TabletCounters->Simple()[COUNTER_USER_ATTRIBUTES_COUNT].Sub(path->UserAttrs->Size()); - context.SS->PersistUserAttributes(db, path->PathId, path->UserAttrs, nullptr); - - ++parentDir->DirAlterVersion; - context.SS->PersistPathDirAlterVersion(db, parentDir); - context.SS->ClearDescribePathCaches(parentDir); - context.OnComplete.PublishToSchemeBoard(OperationId, parentDir->PathId); - - context.SS->ClearDescribePathCaches(path); - context.OnComplete.PublishToSchemeBoard(OperationId, pathId); - - context.OnComplete.DoneOperation(OperationId); - - return true; - } - - bool ProgressState(TOperationContext& context) override { - const auto ssId = context.SS->SelfTabletId(); - - LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - DebugHint() << " ProgressState" - << ", at schemeshard: " << ssId); - - auto* txState = context.SS->FindTx(OperationId); - Y_VERIFY(txState); - Y_VERIFY(txState->TxType == TTxState::TxDropFileStore); - - context.OnComplete.ProposeToCoordinator(OperationId, txState->TargetPathId, TStepId(0)); - return false; - } -}; - -//////////////////////////////////////////////////////////////////////////////// - -class TDropFileStore: public TSubOperation { -private: - const TOperationId OperationId; - const TTxTransaction Transaction; - - TTxState::ETxState State = TTxState::Invalid; - -public: - TDropFileStore(TOperationId id, const TTxTransaction& tx) - : OperationId(id) - , Transaction(tx) - { - } - - TDropFileStore(TOperationId id, TTxState::ETxState state) - : OperationId(id) - , State(state) - { - SetState(SelectStateFunc(state)); - } - - THolder<TProposeResponse> Propose( - const TString& owner, - TOperationContext& context) override; - - void AbortPropose(TOperationContext&) override { - Y_FAIL("no AbortPropose for TDropFileStore"); - } - - void AbortUnsafe(TTxId forceDropTxId, TOperationContext& context) override { - LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "TDropFileStore AbortUnsafe" - << ", opId: " << OperationId - << ", forceDropId: " << forceDropTxId - << ", at schemeshard: " << context.SS->TabletID()); - - auto* txState = context.SS->FindTx(OperationId); - Y_VERIFY(txState); - - TPathId pathId = txState->TargetPathId; - Y_VERIFY(context.SS->PathsById.contains(pathId)); - - TPathElement::TPtr path = context.SS->PathsById.at(pathId); - Y_VERIFY(path); - - if (path->Dropped()) { - for (const auto& shard: txState->Shards) { - context.OnComplete.DeleteShard(shard.Idx); - } - } - - context.OnComplete.DoneOperation(OperationId); - } - - void StateDone(TOperationContext& context) override { - State = NextState(State); - - if (State != TTxState::Invalid) { - SetState(SelectStateFunc(State)); - context.OnComplete.ActivateTx(OperationId); - } - } - -private: - TTxState::ETxState NextState() { - return TTxState::DeleteParts; - } - - TTxState::ETxState NextState(TTxState::ETxState state) { - switch(state) { - case TTxState::Waiting: - case TTxState::DeleteParts: - return TTxState::Propose; - default: - return TTxState::Invalid; - } - return TTxState::Invalid; - } - - TSubOperationState::TPtr SelectStateFunc(TTxState::ETxState state) { - switch(state) { - case TTxState::Waiting: - case TTxState::DeleteParts: + context.SS->PersistUserAttributes(db, path->PathId, path->UserAttrs, nullptr); + + ++parentDir->DirAlterVersion; + context.SS->PersistPathDirAlterVersion(db, parentDir); + context.SS->ClearDescribePathCaches(parentDir); + context.OnComplete.PublishToSchemeBoard(OperationId, parentDir->PathId); + + context.SS->ClearDescribePathCaches(path); + context.OnComplete.PublishToSchemeBoard(OperationId, pathId); + + context.OnComplete.DoneOperation(OperationId); + + return true; + } + + bool ProgressState(TOperationContext& context) override { + const auto ssId = context.SS->SelfTabletId(); + + LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + DebugHint() << " ProgressState" + << ", at schemeshard: " << ssId); + + auto* txState = context.SS->FindTx(OperationId); + Y_VERIFY(txState); + Y_VERIFY(txState->TxType == TTxState::TxDropFileStore); + + context.OnComplete.ProposeToCoordinator(OperationId, txState->TargetPathId, TStepId(0)); + return false; + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class TDropFileStore: public TSubOperation { +private: + const TOperationId OperationId; + const TTxTransaction Transaction; + + TTxState::ETxState State = TTxState::Invalid; + +public: + TDropFileStore(TOperationId id, const TTxTransaction& tx) + : OperationId(id) + , Transaction(tx) + { + } + + TDropFileStore(TOperationId id, TTxState::ETxState state) + : OperationId(id) + , State(state) + { + SetState(SelectStateFunc(state)); + } + + THolder<TProposeResponse> Propose( + const TString& owner, + TOperationContext& context) override; + + void AbortPropose(TOperationContext&) override { + Y_FAIL("no AbortPropose for TDropFileStore"); + } + + void AbortUnsafe(TTxId forceDropTxId, TOperationContext& context) override { + LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + "TDropFileStore AbortUnsafe" + << ", opId: " << OperationId + << ", forceDropId: " << forceDropTxId + << ", at schemeshard: " << context.SS->TabletID()); + + auto* txState = context.SS->FindTx(OperationId); + Y_VERIFY(txState); + + TPathId pathId = txState->TargetPathId; + Y_VERIFY(context.SS->PathsById.contains(pathId)); + + TPathElement::TPtr path = context.SS->PathsById.at(pathId); + Y_VERIFY(path); + + if (path->Dropped()) { + for (const auto& shard: txState->Shards) { + context.OnComplete.DeleteShard(shard.Idx); + } + } + + context.OnComplete.DoneOperation(OperationId); + } + + void StateDone(TOperationContext& context) override { + State = NextState(State); + + if (State != TTxState::Invalid) { + SetState(SelectStateFunc(State)); + context.OnComplete.ActivateTx(OperationId); + } + } + +private: + TTxState::ETxState NextState() { + return TTxState::DeleteParts; + } + + TTxState::ETxState NextState(TTxState::ETxState state) { + switch(state) { + case TTxState::Waiting: + case TTxState::DeleteParts: + return TTxState::Propose; + default: + return TTxState::Invalid; + } + return TTxState::Invalid; + } + + TSubOperationState::TPtr SelectStateFunc(TTxState::ETxState state) { + switch(state) { + case TTxState::Waiting: + case TTxState::DeleteParts: return MakeHolder<TDeleteParts>(OperationId); - case TTxState::Propose: + case TTxState::Propose: return MakeHolder<TPropose>(OperationId); - default: - return nullptr; - } - } -}; - -//////////////////////////////////////////////////////////////////////////////// - -THolder<TProposeResponse> TDropFileStore::Propose( - const TString& owner, - TOperationContext& context) -{ - Y_UNUSED(owner); - - const auto ssId = context.SS->SelfTabletId(); - - const auto& operation = Transaction.GetDrop(); - const TString& parentPathStr = Transaction.GetWorkingDir(); - const TString& name = operation.GetName(); - - LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "TDropFileStore Propose" - << ", path: " << parentPathStr << "/" << name - << ", pathId: " << operation.GetId() - << ", opId: " << OperationId - << ", at schemeshard: " << ssId); - - auto result = MakeHolder<TProposeResponse>( + default: + return nullptr; + } + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +THolder<TProposeResponse> TDropFileStore::Propose( + const TString& owner, + TOperationContext& context) +{ + Y_UNUSED(owner); + + const auto ssId = context.SS->SelfTabletId(); + + const auto& operation = Transaction.GetDrop(); + const TString& parentPathStr = Transaction.GetWorkingDir(); + const TString& name = operation.GetName(); + + LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + "TDropFileStore Propose" + << ", path: " << parentPathStr << "/" << name + << ", pathId: " << operation.GetId() + << ", opId: " << OperationId + << ", at schemeshard: " << ssId); + + auto result = MakeHolder<TProposeResponse>( NKikimrScheme::StatusAccepted, - ui64(OperationId.GetTxId()), - ui64(ssId)); - - TPath path = operation.HasId() - ? TPath::Init(context.SS->MakeLocalId(operation.GetId()), context.SS) - : TPath::Resolve(parentPathStr, context.SS).Dive(name); - - { - auto checks = path.Check(); - checks - .NotEmpty() - .NotUnderDomainUpgrade() - .IsAtLocalSchemeShard() - .IsResolved() - .NotDeleted() - .IsFileStore() - .NotUnderDeleting() - .NotUnderOperation() - .IsCommonSensePath(); - - if (!checks) { - TString explain = TStringBuilder() - << "path table fail checks" - << ", path: " << path.PathString(); - - auto status = checks.GetStatus(&explain); - result->SetError(status, explain); - if (path.IsResolved() && path.Base()->IsFileStore() && path.Base()->PlannedToDrop()) { - result->SetPathDropTxId(ui64(path.Base()->DropTxId)); - result->SetPathId(path.Base()->PathId.LocalPathId); - } - return result; - } - } - - TString errStr; - if (!context.SS->CheckApplyIf(Transaction, errStr)) { + ui64(OperationId.GetTxId()), + ui64(ssId)); + + TPath path = operation.HasId() + ? TPath::Init(context.SS->MakeLocalId(operation.GetId()), context.SS) + : TPath::Resolve(parentPathStr, context.SS).Dive(name); + + { + auto checks = path.Check(); + checks + .NotEmpty() + .NotUnderDomainUpgrade() + .IsAtLocalSchemeShard() + .IsResolved() + .NotDeleted() + .IsFileStore() + .NotUnderDeleting() + .NotUnderOperation() + .IsCommonSensePath(); + + if (!checks) { + TString explain = TStringBuilder() + << "path table fail checks" + << ", path: " << path.PathString(); + + auto status = checks.GetStatus(&explain); + result->SetError(status, explain); + if (path.IsResolved() && path.Base()->IsFileStore() && path.Base()->PlannedToDrop()) { + result->SetPathDropTxId(ui64(path.Base()->DropTxId)); + result->SetPathId(path.Base()->PathId.LocalPathId); + } + return result; + } + } + + TString errStr; + if (!context.SS->CheckApplyIf(Transaction, errStr)) { result->SetError(NKikimrScheme::StatusPreconditionFailed, errStr); - return result; - } - - TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxDropFileStore, path.Base()->PathId); - // Dirty hack: operation step must not be zero because 0 is treated as "hasn't been operationped" - txState.MinStep = TStepId(1); - txState.State = TTxState::DeleteParts; - - NIceDb::TNiceDb db(context.Txc.DB); - - auto fs = context.SS->FileStoreInfos.at(path.Base()->PathId); - Y_VERIFY_S(fs, "FileStore info is null. PathId: " << path.Base()->PathId); - - { - auto shardIdx = fs->IndexShardIdx; + return result; + } + + TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxDropFileStore, path.Base()->PathId); + // Dirty hack: operation step must not be zero because 0 is treated as "hasn't been operationped" + txState.MinStep = TStepId(1); + txState.State = TTxState::DeleteParts; + + NIceDb::TNiceDb db(context.Txc.DB); + + auto fs = context.SS->FileStoreInfos.at(path.Base()->PathId); + Y_VERIFY_S(fs, "FileStore info is null. PathId: " << path.Base()->PathId); + + { + auto shardIdx = fs->IndexShardIdx; Y_VERIFY_S(context.SS->ShardInfos.count(shardIdx), "invalid schemeshard idx " << shardIdx << " at " << path.Base()->PathId); - txState.Shards.emplace_back(shardIdx, context.SS->ShardInfos.at(shardIdx).TabletType, txState.State); - - context.SS->ShardInfos.at(shardIdx).CurrentTxId = OperationId.GetTxId(); - context.SS->PersistShardTx(db, shardIdx, OperationId.GetTxId()); - } - - // Trying to abort Alter/Create. Wait if can't. - context.OnComplete.ActivateTx(OperationId); + txState.Shards.emplace_back(shardIdx, context.SS->ShardInfos.at(shardIdx).TabletType, txState.State); + + context.SS->ShardInfos.at(shardIdx).CurrentTxId = OperationId.GetTxId(); + context.SS->PersistShardTx(db, shardIdx, OperationId.GetTxId()); + } + + // Trying to abort Alter/Create. Wait if can't. + context.OnComplete.ActivateTx(OperationId); context.SS->PersistTxState(db, OperationId); - - path.Base()->PathState = TPathElement::EPathState::EPathStateDrop; - path.Base()->DropTxId = OperationId.GetTxId(); - path.Base()->LastTxId = OperationId.GetTxId(); - + + path.Base()->PathState = TPathElement::EPathState::EPathStateDrop; + path.Base()->DropTxId = OperationId.GetTxId(); + path.Base()->LastTxId = OperationId.GetTxId(); + context.SS->TabletCounters->Simple()[COUNTER_FILESTORE_COUNT].Sub(1); - - auto parentDir = path.Parent(); - ++parentDir.Base()->DirAlterVersion; - context.SS->PersistPathDirAlterVersion(db, parentDir.Base()); - context.SS->ClearDescribePathCaches(parentDir.Base()); - context.OnComplete.PublishToSchemeBoard(OperationId, parentDir.Base()->PathId); - - context.SS->ClearDescribePathCaches(path.Base()); - context.OnComplete.PublishToSchemeBoard(OperationId, path.Base()->PathId); - - State = NextState(); - SetState(SelectStateFunc(State)); - return result; -} - -} // namespace - -namespace NKikimr { + + auto parentDir = path.Parent(); + ++parentDir.Base()->DirAlterVersion; + context.SS->PersistPathDirAlterVersion(db, parentDir.Base()); + context.SS->ClearDescribePathCaches(parentDir.Base()); + context.OnComplete.PublishToSchemeBoard(OperationId, parentDir.Base()->PathId); + + context.SS->ClearDescribePathCaches(path.Base()); + context.OnComplete.PublishToSchemeBoard(OperationId, path.Base()->PathId); + + State = NextState(); + SetState(SelectStateFunc(State)); + return result; +} + +} // namespace + +namespace NKikimr { namespace NSchemeShard { - -//////////////////////////////////////////////////////////////////////////////// - -ISubOperationBase::TPtr CreateDropFileStore(TOperationId id, const TTxTransaction& tx) { - return new TDropFileStore(id, tx); -} - -ISubOperationBase::TPtr CreateDropFileStore(TOperationId id, TTxState::ETxState state) { - Y_VERIFY(state != TTxState::Invalid); - return new TDropFileStore(id, state); -} - + +//////////////////////////////////////////////////////////////////////////////// + +ISubOperationBase::TPtr CreateDropFileStore(TOperationId id, const TTxTransaction& tx) { + return new TDropFileStore(id, tx); +} + +ISubOperationBase::TPtr CreateDropFileStore(TOperationId id, TTxState::ETxState state) { + Y_VERIFY(state != TTxState::Invalid); + return new TDropFileStore(id, state); +} + } // namespace NSchemeShard -} // namespace NKikimr +} // namespace NKikimr diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_part.h b/ydb/core/tx/schemeshard/schemeshard__operation_part.h index ae70925a41..4a639e6342 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_part.h +++ b/ydb/core/tx/schemeshard/schemeshard__operation_part.h @@ -369,15 +369,15 @@ ISubOperationBase::TPtr CreateLockForIndexBuild(TOperationId id, TTxState::ETxSt ISubOperationBase::TPtr DropLock(TOperationId id, const TTxTransaction& tx); ISubOperationBase::TPtr DropLock(TOperationId id, TTxState::ETxState state); -ISubOperationBase::TPtr CreateNewFileStore(TOperationId id, const TTxTransaction& tx); -ISubOperationBase::TPtr CreateNewFileStore(TOperationId id, TTxState::ETxState state); - -ISubOperationBase::TPtr CreateAlterFileStore(TOperationId id, const TTxTransaction& tx); -ISubOperationBase::TPtr CreateAlterFileStore(TOperationId id, TTxState::ETxState state); - -ISubOperationBase::TPtr CreateDropFileStore(TOperationId id, const TTxTransaction& tx); -ISubOperationBase::TPtr CreateDropFileStore(TOperationId id, TTxState::ETxState state); - +ISubOperationBase::TPtr CreateNewFileStore(TOperationId id, const TTxTransaction& tx); +ISubOperationBase::TPtr CreateNewFileStore(TOperationId id, TTxState::ETxState state); + +ISubOperationBase::TPtr CreateAlterFileStore(TOperationId id, const TTxTransaction& tx); +ISubOperationBase::TPtr CreateAlterFileStore(TOperationId id, TTxState::ETxState state); + +ISubOperationBase::TPtr CreateDropFileStore(TOperationId id, const TTxTransaction& tx); +ISubOperationBase::TPtr CreateDropFileStore(TOperationId id, TTxState::ETxState state); + ISubOperationBase::TPtr CreateAlterLogin(TOperationId id, const TTxTransaction& tx); ISubOperationBase::TPtr CreateAlterLogin(TOperationId id, TTxState::ETxState state); diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.cpp b/ydb/core/tx/schemeshard/schemeshard_impl.cpp index b978b3dfe4..0715543a22 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_impl.cpp @@ -1227,7 +1227,7 @@ TPathElement::EPathState TSchemeShard::CalcPathState(TTxState::ETxType txType, T case TTxState::TxCreateSubDomain: case TTxState::TxCreateExtSubDomain: case TTxState::TxCreateBlockStoreVolume: - case TTxState::TxCreateFileStore: + case TTxState::TxCreateFileStore: case TTxState::TxCreateKesus: case TTxState::TxCreateSolomonVolume: case TTxState::TxCreateRtmrVolume: @@ -1241,7 +1241,7 @@ TPathElement::EPathState TSchemeShard::CalcPathState(TTxState::ETxType txType, T case TTxState::TxAlterPQGroup: case TTxState::TxAlterTable: case TTxState::TxAlterBlockStoreVolume: - case TTxState::TxAlterFileStore: + case TTxState::TxAlterFileStore: case TTxState::TxAlterKesus: case TTxState::TxAlterSubDomain: case TTxState::TxAlterExtSubDomain: @@ -1269,7 +1269,7 @@ TPathElement::EPathState TSchemeShard::CalcPathState(TTxState::ETxType txType, T case TTxState::TxForceDropSubDomain: case TTxState::TxForceDropExtSubDomain: case TTxState::TxDropBlockStoreVolume: - case TTxState::TxDropFileStore: + case TTxState::TxDropFileStore: case TTxState::TxDropKesus: case TTxState::TxDropSolomonVolume: case TTxState::TxDropTableIndex: @@ -2763,42 +2763,42 @@ void TSchemeShard::PersistRemoveBlockStoreVolume(NIceDb::TNiceDb& db, TPathId pa } void TSchemeShard::PersistFileStoreInfo(NIceDb::TNiceDb& db, TPathId pathId, const TFileStoreInfo::TPtr fs) -{ - Y_VERIFY(IsLocalId(pathId)); - - TString config; +{ + Y_VERIFY(IsLocalId(pathId)); + + TString config; Y_PROTOBUF_SUPPRESS_NODISCARD fs->Config.SerializeToString(&config); - - db.Table<Schema::FileStoreInfos>() - .Key(pathId.LocalPathId) - .Update( - NIceDb::TUpdate<Schema::FileStoreInfos::Config>(config), - NIceDb::TUpdate<Schema::FileStoreInfos::Version>(fs->Version)); -} - + + db.Table<Schema::FileStoreInfos>() + .Key(pathId.LocalPathId) + .Update( + NIceDb::TUpdate<Schema::FileStoreInfos::Config>(config), + NIceDb::TUpdate<Schema::FileStoreInfos::Version>(fs->Version)); +} + void TSchemeShard::PersistAddFileStoreAlter(NIceDb::TNiceDb& db, TPathId pathId, const TFileStoreInfo::TPtr fs) -{ - Y_VERIFY(IsLocalId(pathId)); - - TString config; +{ + Y_VERIFY(IsLocalId(pathId)); + + TString config; Y_PROTOBUF_SUPPRESS_NODISCARD fs->AlterConfig->SerializeToString(&config); - - db.Table<Schema::FileStoreAlters>() - .Key(pathId.LocalPathId) - .Update( - NIceDb::TUpdate<Schema::FileStoreAlters::Config>(config), - NIceDb::TUpdate<Schema::FileStoreAlters::Version>(fs->AlterVersion)); -} - + + db.Table<Schema::FileStoreAlters>() + .Key(pathId.LocalPathId) + .Update( + NIceDb::TUpdate<Schema::FileStoreAlters::Config>(config), + NIceDb::TUpdate<Schema::FileStoreAlters::Version>(fs->AlterVersion)); +} + void TSchemeShard::PersistRemoveFileStoreAlter(NIceDb::TNiceDb& db, TPathId pathId) -{ - Y_VERIFY(IsLocalId(pathId)); - - db.Table<Schema::FileStoreAlters>() - .Key(pathId.LocalPathId) - .Delete(); -} - +{ + Y_VERIFY(IsLocalId(pathId)); + + db.Table<Schema::FileStoreAlters>() + .Key(pathId.LocalPathId) + .Delete(); +} + void TSchemeShard::PersistRemoveFileStoreInfo(NIceDb::TNiceDb& db, TPathId pathId) { Y_VERIFY(IsLocalId(pathId)); @@ -3934,7 +3934,7 @@ void TSchemeShard::StateWork(STFUNC_SIG) { HFuncTraced(TSchemeBoardEvents::TEvUpdateAck, Handle); HFuncTraced(TEvBlockStore::TEvUpdateVolumeConfigResponse, Handle); - HFuncTraced(TEvFileStore::TEvUpdateConfigResponse, Handle); + HFuncTraced(TEvFileStore::TEvUpdateConfigResponse, Handle); HFuncTraced(NKesus::TEvKesus::TEvSetConfigResult, Handle); HFuncTraced(TEvPersQueue::TEvDropTabletReply, Handle); HFuncTraced(TEvPersQueue::TEvUpdateConfigResponse, Handle); @@ -4253,9 +4253,9 @@ void TSchemeShard::UncountNode(TPathElement::TPtr node) { case TPathElement::EPathType::EPathTypeBlockStoreVolume: TabletCounters->Simple()[COUNTER_BLOCKSTORE_VOLUME_COUNT].Sub(1); break; - case TPathElement::EPathType::EPathTypeFileStore: + case TPathElement::EPathType::EPathTypeFileStore: TabletCounters->Simple()[COUNTER_FILESTORE_COUNT].Sub(1); - break; + break; case TPathElement::EPathType::EPathTypeKesus: TabletCounters->Simple()[COUNTER_KESUS_COUNT].Sub(1); break; @@ -5051,29 +5051,29 @@ void TSchemeShard::Handle(TEvBlockStore::TEvUpdateVolumeConfigResponse::TPtr& ev } void TSchemeShard::Handle(TEvFileStore::TEvUpdateConfigResponse::TPtr& ev, const TActorContext& ctx) { - const auto txId = TTxId(ev->Get()->Record.GetTxId()); - if (!Operations.contains(txId)) { - LOG_WARN_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "Got TEvFileStore::TEvUpdateConfigResponse" - << " for unknown txId " << txId - << " tabletId " << ev->Get()->Record.GetOrigin()); - return; - } - - auto tabletId = TTabletId(ev->Get()->Record.GetOrigin()); - auto partId = Operations.at(txId)->FindRelatedPartByTabletId(tabletId, ctx); - if (partId == InvalidSubTxId) { - LOG_WARN_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "Got TEvUpdateVolumeConfigResponse but partId in unknown" - << ", for txId: " << txId - << ", tabletId: " << tabletId - << ", at schemeshard: " << TabletID()); - return; - } - - Execute(CreateTxOperationReply(TOperationId(txId, partId), ev), ctx); -} - + const auto txId = TTxId(ev->Get()->Record.GetTxId()); + if (!Operations.contains(txId)) { + LOG_WARN_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + "Got TEvFileStore::TEvUpdateConfigResponse" + << " for unknown txId " << txId + << " tabletId " << ev->Get()->Record.GetOrigin()); + return; + } + + auto tabletId = TTabletId(ev->Get()->Record.GetOrigin()); + auto partId = Operations.at(txId)->FindRelatedPartByTabletId(tabletId, ctx); + if (partId == InvalidSubTxId) { + LOG_WARN_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, + "Got TEvUpdateVolumeConfigResponse but partId in unknown" + << ", for txId: " << txId + << ", tabletId: " << tabletId + << ", at schemeshard: " << TabletID()); + return; + } + + Execute(CreateTxOperationReply(TOperationId(txId, partId), ev), ctx); +} + void TSchemeShard::Handle(TEvSchemeShard::TEvInitTenantSchemeShardResult::TPtr& ev, const TActorContext& ctx) { const auto& record = ev->Get()->Record; auto tabletId = TTabletId(record.GetTenantSchemeShard()); diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.h b/ydb/core/tx/schemeshard/schemeshard_impl.h index 6cb42b4be9..e1a1d08b9a 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.h +++ b/ydb/core/tx/schemeshard/schemeshard_impl.h @@ -47,7 +47,7 @@ #include <ydb/core/blockstore/core/blockstore.h> #include <ydb/core/filestore/core/filestore.h> - + #include <ydb/library/login/login.h> #include <util/generic/ptr.h> @@ -168,7 +168,7 @@ public: THashMap<TPathId, TSolomonVolumeInfo::TPtr> SolomonVolumes; THashMap<TPathId, TSubDomainInfo::TPtr> SubDomains; THashMap<TPathId, TBlockStoreVolumeInfo::TPtr> BlockStoreVolumes; - THashMap<TPathId, TFileStoreInfo::TPtr> FileStoreInfos; + THashMap<TPathId, TFileStoreInfo::TPtr> FileStoreInfos; THashMap<TPathId, TKesusInfo::TPtr> KesusInfos; THashMap<TPathId, TOlapStoreInfo::TPtr> OlapStores; THashMap<TPathId, TOlapTableInfo::TPtr> OlapTables; @@ -528,21 +528,21 @@ public: void PersistRemoveTable(NIceDb::TNiceDb& db, TPathId tableId, const TActorContext& ctx); void PersistRevertedMirgration(NIceDb::TNiceDb& db, TPathId pathId, TTabletId abandonedSchemeShardId); - // BlockStore - void PersistBlockStorePartition(NIceDb::TNiceDb& db, TPathId pathId, ui32 partitionId, TShardIdx shardIdx, ui64 version); - void PersistBlockStoreVolume(NIceDb::TNiceDb& db, TPathId pathId, const TBlockStoreVolumeInfo::TPtr); - void PersistBlockStoreVolumeMountToken(NIceDb::TNiceDb& db, TPathId pathId, const TBlockStoreVolumeInfo::TPtr volume); - void PersistAddBlockStoreVolumeAlter(NIceDb::TNiceDb& db, TPathId pathId, const TBlockStoreVolumeInfo::TPtr); - void PersistRemoveBlockStoreVolumeAlter(NIceDb::TNiceDb& db, TPathId pathId); + // BlockStore + void PersistBlockStorePartition(NIceDb::TNiceDb& db, TPathId pathId, ui32 partitionId, TShardIdx shardIdx, ui64 version); + void PersistBlockStoreVolume(NIceDb::TNiceDb& db, TPathId pathId, const TBlockStoreVolumeInfo::TPtr); + void PersistBlockStoreVolumeMountToken(NIceDb::TNiceDb& db, TPathId pathId, const TBlockStoreVolumeInfo::TPtr volume); + void PersistAddBlockStoreVolumeAlter(NIceDb::TNiceDb& db, TPathId pathId, const TBlockStoreVolumeInfo::TPtr); + void PersistRemoveBlockStoreVolumeAlter(NIceDb::TNiceDb& db, TPathId pathId); void PersistRemoveBlockStorePartition(NIceDb::TNiceDb& db, TPathId pathId, ui32 partitionId); void PersistRemoveBlockStoreVolume(NIceDb::TNiceDb& db, TPathId pathId); - - // FileStore - void PersistFileStoreInfo(NIceDb::TNiceDb& db, TPathId pathId, const TFileStoreInfo::TPtr); - void PersistAddFileStoreAlter(NIceDb::TNiceDb& db, TPathId pathId, const TFileStoreInfo::TPtr); - void PersistRemoveFileStoreAlter(NIceDb::TNiceDb& db, TPathId pathId); + + // FileStore + void PersistFileStoreInfo(NIceDb::TNiceDb& db, TPathId pathId, const TFileStoreInfo::TPtr); + void PersistAddFileStoreAlter(NIceDb::TNiceDb& db, TPathId pathId, const TFileStoreInfo::TPtr); + void PersistRemoveFileStoreAlter(NIceDb::TNiceDb& db, TPathId pathId); void PersistRemoveFileStoreInfo(NIceDb::TNiceDb& db, TPathId pathId); - + // OlapStore void PersistOlapStore(NIceDb::TNiceDb& db, TPathId pathId, const TOlapStoreInfo& storeInfo, bool isAlter = false); void PersistOlapStoreRemove(NIceDb::TNiceDb& db, TPathId pathId, bool isAlter = false); @@ -783,7 +783,7 @@ public: void Handle(TEvPersQueue::TEvUpdateConfigResponse::TPtr &ev, const TActorContext &ctx); void Handle(TEvSubDomain::TEvConfigureStatus::TPtr &ev, const TActorContext &ctx); void Handle(TEvBlockStore::TEvUpdateVolumeConfigResponse::TPtr& ev, const TActorContext& ctx); - void Handle(TEvFileStore::TEvUpdateConfigResponse::TPtr& ev, const TActorContext& ctx); + void Handle(TEvFileStore::TEvUpdateConfigResponse::TPtr& ev, const TActorContext& ctx); void Handle(NKesus::TEvKesus::TEvSetConfigResult::TPtr& ev, const TActorContext& ctx); void Handle(TEvSchemeShard::TEvInitTenantSchemeShardResult::TPtr& ev, const TActorContext& ctx); void Handle(TEvSchemeShard::TEvPublishTenantAsReadOnly::TPtr& ev, const TActorContext& ctx); diff --git a/ydb/core/tx/schemeshard/schemeshard_info_types.h b/ydb/core/tx/schemeshard/schemeshard_info_types.h index d381416dde..2e5710c3d3 100644 --- a/ydb/core/tx/schemeshard/schemeshard_info_types.h +++ b/ydb/core/tx/schemeshard/schemeshard_info_types.h @@ -921,10 +921,10 @@ struct TShardInfo { return TShardInfo(txId, pathId, ETabletType::BlockStorePartition2); } - static TShardInfo FileStoreInfo(TTxId txId, TPathId pathId) { - return TShardInfo(txId, pathId, ETabletType::FileStore); - } - + static TShardInfo FileStoreInfo(TTxId txId, TPathId pathId) { + return TShardInfo(txId, pathId, ETabletType::FileStore); + } + static TShardInfo KesusInfo(TTxId txId, TPathId pathId) { return TShardInfo(txId, pathId, ETabletType::Kesus); } @@ -1984,44 +1984,44 @@ struct TBlockStoreVolumeInfo : public TSimpleRefCount<TBlockStoreVolumeInfo> { } }; -struct TFileStoreInfo : public TSimpleRefCount<TFileStoreInfo> { - using TPtr = TIntrusivePtr<TFileStoreInfo>; - - TShardIdx IndexShardIdx = InvalidShardIdx; - TTabletId IndexTabletId = InvalidTabletId; - - NKikimrFileStore::TConfig Config; - ui64 Version = 0; - - THolder<NKikimrFileStore::TConfig> AlterConfig; - ui64 AlterVersion = 0; - - void PrepareAlter(const NKikimrFileStore::TConfig& alterConfig) { - Y_VERIFY(!AlterConfig); - Y_VERIFY(!AlterVersion); - +struct TFileStoreInfo : public TSimpleRefCount<TFileStoreInfo> { + using TPtr = TIntrusivePtr<TFileStoreInfo>; + + TShardIdx IndexShardIdx = InvalidShardIdx; + TTabletId IndexTabletId = InvalidTabletId; + + NKikimrFileStore::TConfig Config; + ui64 Version = 0; + + THolder<NKikimrFileStore::TConfig> AlterConfig; + ui64 AlterVersion = 0; + + void PrepareAlter(const NKikimrFileStore::TConfig& alterConfig) { + Y_VERIFY(!AlterConfig); + Y_VERIFY(!AlterVersion); + AlterConfig = MakeHolder<NKikimrFileStore::TConfig>(); AlterConfig->CopyFrom(alterConfig); - + Y_VERIFY(!AlterConfig->GetBlockSize()); AlterConfig->SetBlockSize(Config.GetBlockSize()); - AlterVersion = Version + 1; - } - - void FinishAlter() { - Y_VERIFY(AlterConfig); - Y_VERIFY(AlterVersion); - - Config.CopyFrom(*AlterConfig); - ++Version; - Y_VERIFY(Version == AlterVersion); - - AlterConfig.Reset(); - AlterVersion = 0; - } -}; - + AlterVersion = Version + 1; + } + + void FinishAlter() { + Y_VERIFY(AlterConfig); + Y_VERIFY(AlterVersion); + + Config.CopyFrom(*AlterConfig); + ++Version; + Y_VERIFY(Version == AlterVersion); + + AlterConfig.Reset(); + AlterVersion = 0; + } +}; + struct TKesusInfo : public TSimpleRefCount<TKesusInfo> { using TPtr = TIntrusivePtr<TKesusInfo>; diff --git a/ydb/core/tx/schemeshard/schemeshard_path.cpp b/ydb/core/tx/schemeshard/schemeshard_path.cpp index 96f2e24a0e..7535ee673c 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_path.cpp @@ -490,23 +490,23 @@ const TPath::TChecker& TPath::TChecker::IsBlockStoreVolume(TPath::TChecker::ESta return *this; } -const TPath::TChecker& TPath::TChecker::IsFileStore(TPath::TChecker::EStatus status) const { - if (Failed) { - return *this; - } - - if (Path.Base()->IsFileStore()) { - return *this; - } - - Failed = true; - Status = status; - Explain << "path is not a FileStore" - << ", pathId: " << Path.Base()->PathId +const TPath::TChecker& TPath::TChecker::IsFileStore(TPath::TChecker::EStatus status) const { + if (Failed) { + return *this; + } + + if (Path.Base()->IsFileStore()) { + return *this; + } + + Failed = true; + Status = status; + Explain << "path is not a FileStore" + << ", pathId: " << Path.Base()->PathId << ", path type: " << NKikimrSchemeOp::EPathType_Name(Path.Base()->PathType); - return *this; -} - + return *this; +} + const TPath::TChecker& TPath::TChecker::IsKesus(TPath::TChecker::EStatus status) const { if (Failed) { return *this; diff --git a/ydb/core/tx/schemeshard/schemeshard_path.h b/ydb/core/tx/schemeshard/schemeshard_path.h index 0bdbe6af25..fb33c1cdd9 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path.h +++ b/ydb/core/tx/schemeshard/schemeshard_path.h @@ -62,7 +62,7 @@ public: const TChecker& IsTable(EStatus status = EStatus::StatusNameConflict) const; const TChecker& NotBackupTable(EStatus status = NKikimrScheme::StatusSchemeError) const; const TChecker& IsBlockStoreVolume(EStatus status = EStatus::StatusNameConflict) const; - const TChecker& IsFileStore(EStatus status = EStatus::StatusNameConflict) const; + const TChecker& IsFileStore(EStatus status = EStatus::StatusNameConflict) const; const TChecker& IsKesus(EStatus status = EStatus::StatusNameConflict) const; const TChecker& IsPQGroup(EStatus status = EStatus::StatusNameConflict) const; const TChecker& IsSubDomain(EStatus status = EStatus::StatusNameConflict) const; diff --git a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp index d056e4d54a..3789d3af1b 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp @@ -684,25 +684,25 @@ void TPathDescriber::DescribeBlockStoreVolume(TPathId pathId, TPathElement::TPtr } } -void TPathDescriber::DescribeFileStore(TPathId pathId, TPathElement::TPtr pathEl) { - Y_VERIFY(pathEl->IsFileStore()); - auto it = Self->FileStoreInfos.FindPtr(pathId); - Y_VERIFY(it, "FileStore info is not found"); - TFileStoreInfo::TPtr fs = *it; - - auto* entry = Result->Record.MutablePathDescription()->MutableFileStoreDescription(); - entry->SetName(pathEl->Name); - entry->SetPathId(pathId.LocalPathId); - if (fs->IndexTabletId) { - entry->SetIndexTabletId(ui64(fs->IndexTabletId)); - } - entry->SetVersion(fs->Version); - - auto* config = entry->MutableConfig(); - config->CopyFrom(fs->Config); - config->SetVersion(fs->Version); -} - +void TPathDescriber::DescribeFileStore(TPathId pathId, TPathElement::TPtr pathEl) { + Y_VERIFY(pathEl->IsFileStore()); + auto it = Self->FileStoreInfos.FindPtr(pathId); + Y_VERIFY(it, "FileStore info is not found"); + TFileStoreInfo::TPtr fs = *it; + + auto* entry = Result->Record.MutablePathDescription()->MutableFileStoreDescription(); + entry->SetName(pathEl->Name); + entry->SetPathId(pathId.LocalPathId); + if (fs->IndexTabletId) { + entry->SetIndexTabletId(ui64(fs->IndexTabletId)); + } + entry->SetVersion(fs->Version); + + auto* config = entry->MutableConfig(); + config->CopyFrom(fs->Config); + config->SetVersion(fs->Version); +} + void TPathDescriber::DescribeKesus(TPathId pathId, TPathElement::TPtr pathEl) { Y_VERIFY(pathEl->IsKesus()); auto it = Self->KesusInfos.FindPtr(pathId); diff --git a/ydb/core/tx/schemeshard/schemeshard_path_describer.h b/ydb/core/tx/schemeshard/schemeshard_path_describer.h index 6e6fd6240b..7d10ed1da7 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path_describer.h +++ b/ydb/core/tx/schemeshard/schemeshard_path_describer.h @@ -38,7 +38,7 @@ class TPathDescriber { void DescribeRevertedMigrations(TPathElement::TPtr pathEl); void DescribeBlockStoreVolume(TPathId pathId, TPathElement::TPtr pathEl); - void DescribeFileStore(TPathId pathId, TPathElement::TPtr pathEl); + void DescribeFileStore(TPathId pathId, TPathElement::TPtr pathEl); void DescribeKesus(TPathId pathId, TPathElement::TPtr pathEl); void DescribeSequence(TPathId pathId, TPathElement::TPtr pathEl); void DescribeReplication(TPathId pathId, TPathElement::TPtr pathEl); diff --git a/ydb/core/tx/schemeshard/schemeshard_path_element.h b/ydb/core/tx/schemeshard/schemeshard_path_element.h index 554e7e7fa0..9912880c05 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path_element.h +++ b/ydb/core/tx/schemeshard/schemeshard_path_element.h @@ -436,10 +436,10 @@ public: return PathType == EPathType::EPathTypeBlockStoreVolume; } - bool IsFileStore() const { - return PathType == EPathType::EPathTypeFileStore; - } - + bool IsFileStore() const { + return PathType == EPathType::EPathTypeFileStore; + } + bool IsKesus() const { return PathType == EPathType::EPathTypeKesus; } diff --git a/ydb/core/tx/schemeshard/schemeshard_schema.h b/ydb/core/tx/schemeshard/schemeshard_schema.h index 730401d548..f293136fe8 100644 --- a/ydb/core/tx/schemeshard/schemeshard_schema.h +++ b/ydb/core/tx/schemeshard/schemeshard_schema.h @@ -853,24 +853,24 @@ struct Schema : NIceDb::Schema { using TColumns = TableColumns<PathId, VolumeConfig, AlterVersion, PartitionCount>; }; - struct FileStoreInfos : Table<78> { - struct PathId: Column<1, NScheme::NTypeIds::Uint64> {}; - struct Config: Column<2, NScheme::NTypeIds::String> {}; - struct Version: Column<3, NScheme::NTypeIds::Uint64> {}; - - using TKey = TableKey<PathId>; - using TColumns = TableColumns<PathId, Config, Version>; - }; - - struct FileStoreAlters : Table<79> { - struct PathId: Column<1, NScheme::NTypeIds::Uint64> {}; - struct Config: Column<2, NScheme::NTypeIds::String> {}; - struct Version: Column<3, NScheme::NTypeIds::Uint64> {}; - - using TKey = TableKey<PathId>; - using TColumns = TableColumns<PathId, Config, Version>; - }; - + struct FileStoreInfos : Table<78> { + struct PathId: Column<1, NScheme::NTypeIds::Uint64> {}; + struct Config: Column<2, NScheme::NTypeIds::String> {}; + struct Version: Column<3, NScheme::NTypeIds::Uint64> {}; + + using TKey = TableKey<PathId>; + using TColumns = TableColumns<PathId, Config, Version>; + }; + + struct FileStoreAlters : Table<79> { + struct PathId: Column<1, NScheme::NTypeIds::Uint64> {}; + struct Config: Column<2, NScheme::NTypeIds::String> {}; + struct Version: Column<3, NScheme::NTypeIds::Uint64> {}; + + using TKey = TableKey<PathId>; + using TColumns = TableColumns<PathId, Config, Version>; + }; + struct KesusInfos : Table<26> { struct PathId: Column<1, NScheme::NTypeIds::Uint64> {}; struct Config: Column<2, NScheme::NTypeIds::String> {}; @@ -1663,8 +1663,8 @@ struct Schema : NIceDb::Schema { AlterSolomonVolumes, AlterSolomonPartitions, TablePartitionStats, - SubDomainSchemeQuotas, - FileStoreInfos, + SubDomainSchemeQuotas, + FileStoreInfos, FileStoreAlters, TableIndexDataColumns, TableIndexDataColumnsAlterData, diff --git a/ydb/core/tx/schemeshard/schemeshard_tx_infly.h b/ydb/core/tx/schemeshard/schemeshard_tx_infly.h index 5f8ed4dae1..41a8045155 100644 --- a/ydb/core/tx/schemeshard/schemeshard_tx_infly.h +++ b/ydb/core/tx/schemeshard/schemeshard_tx_infly.h @@ -85,10 +85,10 @@ struct TTxState { item(TxFinalizeBuildIndex, 40) \ item(TxAlterSolomonVolume, 41) \ item(TxDropLock, 42) \ - item(TxDropTableIndexAtMainTable, 43) \ - item(TxCreateFileStore, 44) \ - item(TxAlterFileStore, 45) \ - item(TxDropFileStore, 46) \ + item(TxDropTableIndexAtMainTable, 43) \ + item(TxCreateFileStore, 44) \ + item(TxAlterFileStore, 45) \ + item(TxDropFileStore, 46) \ item(TxRestore, 47) \ item(TxCreateOlapStore, 48) \ item(TxAlterOlapStore, 49) \ @@ -111,9 +111,9 @@ struct TTxState { item(TxAlterReplication, 66) \ item(TxDropReplication, 67) \ - // TX_STATE_TYPE_ENUM + // TX_STATE_TYPE_ENUM - //TxMergeTablePartition only for sensors yet + //TxMergeTablePartition only for sensors yet enum ETxType { TX_STATE_TYPE_ENUM(TX_STATE_DECLARE_ENUM) @@ -299,7 +299,7 @@ struct TTxState { case TxCreateSubDomain: case TxCreateExtSubDomain: case TxCreateBlockStoreVolume: - case TxCreateFileStore: + case TxCreateFileStore: case TxCreateKesus: case TxCreateSolomonVolume: case TxCreateRtmrVolume: @@ -321,7 +321,7 @@ struct TTxState { case TxDropPQGroup: case TxDropSubDomain: case TxDropBlockStoreVolume: - case TxDropFileStore: + case TxDropFileStore: case TxDropKesus: case TxForceDropSubDomain: case TxForceDropExtSubDomain: @@ -346,7 +346,7 @@ struct TTxState { case TxRestore: case TxAlterBlockStoreVolume: case TxAssignBlockStoreVolume: - case TxAlterFileStore: + case TxAlterFileStore: case TxAlterKesus: case TxAlterSubDomain: case TxUpgradeSubDomain: @@ -377,7 +377,7 @@ struct TTxState { case TxDropPQGroup: case TxDropSubDomain: case TxDropBlockStoreVolume: - case TxDropFileStore: + case TxDropFileStore: case TxDropKesus: case TxForceDropSubDomain: case TxForceDropExtSubDomain: @@ -397,7 +397,7 @@ struct TTxState { case TxCreateSubDomain: case TxCreateExtSubDomain: case TxCreateBlockStoreVolume: - case TxCreateFileStore: + case TxCreateFileStore: case TxCreateKesus: case TxCreateSolomonVolume: case TxCreateRtmrVolume: @@ -425,7 +425,7 @@ struct TTxState { case TxRestore: case TxAlterBlockStoreVolume: case TxAssignBlockStoreVolume: - case TxAlterFileStore: + case TxAlterFileStore: case TxAlterKesus: case TxAlterSubDomain: case TxUpgradeSubDomain: @@ -456,7 +456,7 @@ struct TTxState { case TxDropPQGroup: case TxDropSubDomain: case TxDropBlockStoreVolume: - case TxDropFileStore: + case TxDropFileStore: case TxDropKesus: case TxForceDropSubDomain: case TxForceDropExtSubDomain: @@ -480,7 +480,7 @@ struct TTxState { case TxCreateSubDomain: case TxCreateExtSubDomain: case TxCreateBlockStoreVolume: - case TxCreateFileStore: + case TxCreateFileStore: case TxCreateKesus: case TxCreateSolomonVolume: case TxCreateRtmrVolume: @@ -504,7 +504,7 @@ struct TTxState { case TxRestore: case TxAlterBlockStoreVolume: case TxAssignBlockStoreVolume: - case TxAlterFileStore: + case TxAlterFileStore: case TxAlterKesus: case TxAlterSubDomain: case TxAlterExtSubDomain: diff --git a/ydb/core/tx/schemeshard/ya.make b/ydb/core/tx/schemeshard/ya.make index 94a00666b6..ceb87ce388 100644 --- a/ydb/core/tx/schemeshard/ya.make +++ b/ydb/core/tx/schemeshard/ya.make @@ -83,14 +83,14 @@ SRCS( schemeshard__operation_db_changes.cpp schemeshard__operation_alter_bsv.cpp schemeshard__operation_alter_extsubdomain.cpp - schemeshard__operation_alter_fs.cpp - schemeshard__operation_alter_index.cpp + schemeshard__operation_alter_fs.cpp + schemeshard__operation_alter_index.cpp schemeshard__operation_alter_kesus.cpp schemeshard__operation_alter_login.cpp schemeshard__operation_alter_olap_store.cpp schemeshard__operation_alter_olap_table.cpp schemeshard__operation_alter_pq.cpp - schemeshard__operation_alter_solomon.cpp + schemeshard__operation_alter_solomon.cpp schemeshard__operation_alter_subdomain.cpp schemeshard__operation_alter_table.cpp schemeshard__operation_alter_user_attrs.cpp @@ -103,8 +103,8 @@ SRCS( schemeshard__operation_create_backup.cpp schemeshard__operation_create_bsv.cpp schemeshard__operation_create_extsubdomain.cpp - schemeshard__operation_create_fs.cpp - schemeshard__operation_create_index.cpp + schemeshard__operation_create_fs.cpp + schemeshard__operation_create_index.cpp schemeshard__operation_create_indexed_table.cpp schemeshard__operation_create_kesus.cpp schemeshard__operation_create_lock.cpp @@ -120,10 +120,10 @@ SRCS( schemeshard__operation_create_table.cpp schemeshard__operation_drop_bsv.cpp schemeshard__operation_drop_extsubdomain.cpp - schemeshard__operation_drop_fs.cpp + schemeshard__operation_drop_fs.cpp schemeshard__operation_drop_indexed_table.cpp schemeshard__operation_drop_kesus.cpp - schemeshard__operation_drop_lock.cpp + schemeshard__operation_drop_lock.cpp schemeshard__operation_drop_olap_store.cpp schemeshard__operation_drop_olap_table.cpp schemeshard__operation_drop_pq.cpp diff --git a/ydb/core/viewer/browse.h b/ydb/core/viewer/browse.h index f9a0cdfd30..c5716f46a7 100644 --- a/ydb/core/viewer/browse.h +++ b/ydb/core/viewer/browse.h @@ -79,7 +79,7 @@ public: case NKikimrSchemeOp::EPathType::EPathTypeBlockStoreVolume: return NKikimrViewer::EObjectType::BlockStoreVolume; case NKikimrSchemeOp::EPathType::EPathTypeFileStore: - return NKikimrViewer::EObjectType::FileStore; + return NKikimrViewer::EObjectType::FileStore; case NKikimrSchemeOp::EPathType::EPathTypeKesus: return NKikimrViewer::EObjectType::Kesus; case NKikimrSchemeOp::EPathType::EPathTypeSolomonVolume: diff --git a/ydb/core/viewer/protos/viewer.proto b/ydb/core/viewer/protos/viewer.proto index daceceeb87..9f6c822a89 100644 --- a/ydb/core/viewer/protos/viewer.proto +++ b/ydb/core/viewer/protos/viewer.proto @@ -30,7 +30,7 @@ enum EObjectType { Kesus = 16; SolomonVolume = 17; SubDomain = 18; - FileStore = 19; + FileStore = 19; CdcStream = 20; Sequence = 21; Replication = 22; diff --git a/ydb/library/yql/core/file_storage/ut/ya.make b/ydb/library/yql/core/file_storage/ut/ya.make index 720c5bc13e..c19f58203b 100644 --- a/ydb/library/yql/core/file_storage/ut/ya.make +++ b/ydb/library/yql/core/file_storage/ut/ya.make @@ -17,10 +17,10 @@ SRCS( url_mapper_ut.cpp ) -PEERDIR( +PEERDIR( library/cpp/http/server library/cpp/threading/future ydb/library/yql/core/file_storage/http_download -) - +) + END() diff --git a/ydb/library/yql/providers/common/gateway/yql_provider_gateway.h b/ydb/library/yql/providers/common/gateway/yql_provider_gateway.h index e8330c5aba..c4b498e9a1 100644 --- a/ydb/library/yql/providers/common/gateway/yql_provider_gateway.h +++ b/ydb/library/yql/providers/common/gateway/yql_provider_gateway.h @@ -81,11 +81,11 @@ template <typename T> inline void SetPromiseValue(NThreading::TPromise<T>& promise, const NThreading::TFuture<T>& future) { future.Subscribe([=] (const NThreading::TFuture<T>& f) mutable { - try { + try { promise.SetValue(f.GetValue()); - } catch (...) { + } catch (...) { promise.SetException(std::current_exception()); - } + } }); } diff --git a/ydb/public/lib/deprecated/kicli/kicli.h b/ydb/public/lib/deprecated/kicli/kicli.h index 194bf0a2eb..9dc472d231 100644 --- a/ydb/public/lib/deprecated/kicli/kicli.h +++ b/ydb/public/lib/deprecated/kicli/kicli.h @@ -574,7 +574,7 @@ public: BlockStoreVolume, Kesus, SolomonVolume, - FileStore, + FileStore, OlapStore, OlapTable, Sequence, diff --git a/ydb/public/lib/deprecated/kicli/schema.cpp b/ydb/public/lib/deprecated/kicli/schema.cpp index 8da046f345..d1ee0384f8 100644 --- a/ydb/public/lib/deprecated/kicli/schema.cpp +++ b/ydb/public/lib/deprecated/kicli/schema.cpp @@ -98,9 +98,9 @@ void TSchemaObject::Drop() { case EPathType::BlockStoreVolume: drop.SetOperationType(NKikimrSchemeOp::EOperationType::ESchemeOpDropBlockStoreVolume); break; - case EPathType::FileStore: + case EPathType::FileStore: drop.SetOperationType(NKikimrSchemeOp::EOperationType::ESchemeOpDropFileStore); - break; + break; case EPathType::Kesus: drop.SetOperationType(NKikimrSchemeOp::EOperationType::ESchemeOpDropKesus); break; @@ -189,7 +189,7 @@ static TSchemaObject::EPathType GetType(const NKikimrSchemeOp::TDirEntry& entry) case NKikimrSchemeOp::EPathTypeBlockStoreVolume: return TSchemaObject::EPathType::BlockStoreVolume; case NKikimrSchemeOp::EPathTypeFileStore: - return TSchemaObject::EPathType::FileStore; + return TSchemaObject::EPathType::FileStore; case NKikimrSchemeOp::EPathTypeKesus: return TSchemaObject::EPathType::Kesus; case NKikimrSchemeOp::EPathTypeSolomonVolume: diff --git a/ydb/tests/library/harness/kikimr_config.py b/ydb/tests/library/harness/kikimr_config.py index 5377cc910c..57c282b9f4 100644 --- a/ydb/tests/library/harness/kikimr_config.py +++ b/ydb/tests/library/harness/kikimr_config.py @@ -73,8 +73,8 @@ def load_default_yaml(default_tablet_node_ids, ydb_domain_name, static_erasure, for log, level in six.iteritems(log_configs): yaml_dict["log_config"]["entry"].append({"component": log, "level": int(level)}) return yaml_dict - - + + class KikimrConfigGenerator(object): def __init__( self, |