Skip to content

Commit

Permalink
libczmqcontainers: Add internal czmq lib
Browse files Browse the repository at this point in the history
Problem: A bug in the czmq zhashx library would incorrectly
resize the hash.  See:

zeromq/czmq#2173

This would lead to significant performance issues as the hash would
take up far more memory than it should and iteration of the hash
would take an excess amount of time.

A solution to this problem was fixed in:

zeromq/czmq#2174

however the fix will not exist in most OS distributions for some
time.

Solution: We have copied in the zhashx implementation into a new
convenience library libczmqcontainers.  Code was copied from the
master branch at commit d4b1a1d884532e43e82b9055ceb0b84d1db5915c.
The library is copied in verbatim with only minor changes to headers
and header guards.

To avoid excess copying in from czmq, add a file czmq_internal.h
that copies in macros, headers, and typdefs needed by the localized
zhashx.

To avoid symbol collisions, add a file zhashx_map.h that will
convert all internal uses of "zhashx" to "fzhashx".

Add a generic czmq_containers.h, that callers can include to use
the internal zhashx over the shared library version.

All files containing copied in code maintain their czmq license
(Mozilla Public License Version 2.0).  All modifications to czmq
files and code were isolated to those files, no code from other
parts of flux-core were copied in. See:

https://www.mozilla.org/en-US/MPL/2.0/combining-mpl-and-gpl/
  • Loading branch information
chu11 committed Apr 16, 2021
1 parent 7aaea06 commit a5cd32a
Show file tree
Hide file tree
Showing 9 changed files with 2,172 additions and 1 deletion.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ AC_CONFIG_FILES( \
src/common/libterminus/Makefile \
src/common/libhostlist/Makefile \
src/common/librlist/Makefile \
src/common/libczmqcontainers/Makefile \
src/bindings/Makefile \
src/bindings/lua/Makefile \
src/bindings/python/Makefile \
Expand Down
4 changes: 3 additions & 1 deletion src/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SUBDIRS = \
libterminus \
libcontent \
libhostlist \
librlist
librlist \
libczmqcontainers

AM_CFLAGS = $(WARNING_CFLAGS) $(CODE_COVERAGE_CFLAGS)
AM_LDFLAGS = $(CODE_COVERAGE_LIBS)
Expand All @@ -42,6 +43,7 @@ libflux_internal_la_LIBADD = \
$(builddir)/libioencode/libioencode.la \
$(builddir)/librouter/librouter.la \
$(builddir)/libhostlist/libhostlist.la \
$(builddir)/libczmqcontainers/libczmqcontainers.la \
$(JANSSON_LIBS) \
$(ZMQ_LIBS) \
$(LIBUUID_LIBS) \
Expand Down
22 changes: 22 additions & 0 deletions src/common/libczmqcontainers/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
AM_CFLAGS = \
$(WARNING_CFLAGS) \
$(CODE_COVERAGE_CFLAGS)

AM_LDFLAGS = \
$(CODE_COVERAGE_LDFLAGS)

AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/src/include \
$(ZMQ_CFLAGS)

noinst_LTLIBRARIES = \
libczmqcontainers.la

libczmqcontainers_la_SOURCES = \
czmq_containers.h \
czmq_internal.h \
zhashx.h \
zhashx.c \
zhash_primes.inc \
zhashx_map.h
24 changes: 24 additions & 0 deletions src/common/libczmqcontainers/czmq_containers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/************************************************************\
* Copyright 2021 Lawrence Livermore National Security, LLC
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/

#ifndef _CZMQ_CONTAINERS_H
#define _CZMQ_CONTAINERS_H

#ifdef __cplusplus
extern "C" {
#endif

#include "zhashx.h"

#ifdef __cplusplus
}
#endif

#endif
42 changes: 42 additions & 0 deletions src/common/libczmqcontainers/czmq_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* =========================================================================
Copyright (c) the Contributors as noted in the AUTHORS file.
This file is part of CZMQ, the high-level C binding for 0MQ:
http://czmq.zeromq.org.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
=========================================================================
*/

/* To avoid copying in an excess amount of code from czmq, the
* following have been manually cut and pasted in
*/

#ifndef __CZMQ_INTERNAL__
#define __CZMQ_INTERNAL__

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdlib.h>

#ifdef NDEBUG
#undef NDEBUG
#include <assert.h>
#define NDEBUG
#else
#include <assert.h>
#endif

#define freen(x) do {free(x); x = NULL;} while(0)

#ifndef CZMQ_EXPORT
#define CZMQ_EXPORT
#endif

typedef struct _zhashx_t fzhashx_t;

#endif

0 comments on commit a5cd32a

Please sign in to comment.