Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Centos 7. SPH_UDF_ARGS. UDF arguments not right initialized #1157

Open
ousharovsky opened this issue Jun 7, 2023 · 3 comments
Open

Centos 7. SPH_UDF_ARGS. UDF arguments not right initialized #1157

ousharovsky opened this issue Jun 7, 2023 · 3 comments
Labels

Comments

@ousharovsky
Copy link

ousharovsky commented Jun 7, 2023

Describe the bug
SPH_UDF_ARGS arguments not right initialized in manticore v 6.0.4 for Centos 7 and 10 million documents index. In Centos 8 and Ubuntu 20.04 all works fine.
There is also no problem for an index of 5 documents for Centos 7.

SPH_UDF_ARGS::arg_values has random or empty values for UDF threads.
SPH_UDF_ARGS::str_lengths may by negative value.

Describe the environment:
searchd --version
Manticore 6.0.4 4c99009@230601
Copyright (c) 2001-2016, Andrew Aksyonoff
Copyright (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)
Copyright (c) 2017-2023, Manticore Software LTD (https://manticoresearch.com)

uname -a
Linux host.domain 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

@sanikolaev
Copy link
Collaborator

@ousharovsky Thanks for filing the issue. Is it possible to get a sample UDF which demonstrates the problem?

@sanikolaev sanikolaev added bug waiting Waiting for the original poster (in most cases) or something else labels Jun 8, 2023
@ousharovsky
Copy link
Author

ousharovsky commented Jun 9, 2023

#include "sphinxudf.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef _MSC_VER
#define snprintf _snprintf
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

/// UDF logging callback
/// write any message into daemon's log.
sphinx_log_fn* sphlog = NULL;

#ifndef NDEBUG
DLLEXPORT void libexactsearch_plugind_setlogcb(sphinx_log_fn* cblog) {
#else
DLLEXPORT void libexactsearch_plugin_setlogcb(sphinx_log_fn* cblog) {
#endif
  sphlog = cblog;
}

void UdfLog(char* szMsg) {
  if (sphlog)
    (*sphlog)(szMsg, -1);
}

#ifndef NDEBUG
DLLEXPORT int libexactsearch_plugind_ver() {
#else
DLLEXPORT int libexactsearch_plugin_ver() {
#endif
  return SPH_UDF_VERSION;
}

DLLEXPORT int strtoint_init(SPH_UDF_INIT* init, SPH_UDF_ARGS* args, char* error_message) {
  UdfLog("Called strtoint_init");
  if (args->arg_count != 1 || args->arg_types[0] != SPH_UDF_TYPE_STRING) {
    snprintf(error_message, SPH_UDF_ERROR_LEN, "STRTOINT() requires 1 string argument");
    return 1;
  }
  return 0;
}

DLLEXPORT sphinx_int64_t strtoint(SPH_UDF_INIT* init, SPH_UDF_ARGS* args, char* error_flag) {
  UdfLog("Called strtoint");
  const char* s = args->arg_values[0];
  int len = args->str_lengths[0], res = 0;

  // looks strange, but let's just take sum of digits, i.e. '123' -> 1+2+3 = 6.
  while (len > 0 && *s >= '0' && *s <= '9') {
    res += *s - '0';
    --len;
    ++s;
  }
  return res;
}
select strtoint('123') from big_index;
+-----------------+
| strtoint('123') |
+-----------------+
|               6 |
|               0 |
|               6 |
|               6 |
|               0 |
|               0 |
|               0 |
|               0 |
|               0 |
|               0 |
|               0 |
|               6 |
|               6 |
|               6 |
|               6 |
|               6 |
|               0 |
|               6 |
|               0 |
|               0 |
+-----------------+
20 rows in set (0,01 sec)

from CMakeList.txt:

set(MODULE_NAME exactsearch_plugin)

@githubmanticore githubmanticore removed the waiting Waiting for the original poster (in most cases) or something else label Jun 12, 2023
@sanikolaev
Copy link
Collaborator

Thanks. We'll look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants