87 Commits

Author SHA1 Message Date
John Sully
aa76a89a9a Merge branch 'unstable' of https://github.com/antirez/redis into unstable
Former-commit-id: be3cb1ad3386f382ed7506dbfd1adb810e327007
2019-03-14 14:22:27 -04:00
John Sully
5ee7a6b8f1 sds copies uninitialized data wasting time for everyone
Former-commit-id: a1475af1e4ab97337287d4ef08d092ffabbb73ca
2019-03-02 19:27:52 -05:00
Guy Benoish
9cd3b12cdf Trim SDS free space of retained module strings
In some cases processMultibulkBuffer uses sdsMakeRoomFor to
expand the querybuf, but later in some cases it uses that query
buffer as is for an argv element (see "Optimization"), which means
that the sds in argv may have a lot of wasted space, and then in case
modules keep that argv RedisString inside their data structure, this
space waste will remain for long (until restarted from rdb).
2019-02-12 14:21:21 +01:00
John Sully
979eb00220 complete malloc memory class work, and pass tests
Former-commit-id: 42d28c9ff6bd0b31ada42bdcbfde3e9fce42fff7
2019-02-04 16:56:13 -05:00
John Sully
9b94405241 Custom flash heap
Former-commit-id: 5c86d2faa2e504d8ccfcafd5646717fef3d333cc
2019-01-29 18:10:46 -05:00
hdmg
7b6cc08d26 fix comments fault discription 2018-12-05 17:15:02 +08:00
Oran Agra
2e2e5dc052 bugfix in sdsReqType creating 64bit sds headers on 32bit systems 2018-07-15 18:24:18 +03:00
Jack Drogon
bae1d36e5d Fix typo 2018-07-03 18:19:46 +02:00
Salvatore Sanfilippo
601420cb73 Merge pull request #3828 from oranagra/sdsnewlen_pr
add SDS_NOINIT option to sdsnewlen to avoid unnecessary memsets.
2018-02-27 04:04:32 -08:00
Oran Agra
5821e8cf82 fix processing of large bulks (above 2GB)
- protocol parsing (processMultibulkBuffer) was limitted to 32big positions in the buffer
  readQueryFromClient potential overflow
- rioWriteBulkCount used int, although rioWriteBulkString gave it size_t
- several places in sds.c that used int for string length or index.
- bugfix in RM_SaveAuxField (return was 1 or -1 and not length)
- RM_SaveStringBuffer was limitted to 32bit length
2017-12-29 12:24:19 +02:00
antirez
899d65cdf4 SDS: improve sdsRemoveFreeSpace() to avoid useless data copy.
Since SDS v2, we no longer have a single header, so the function to
rewrite the SDS in terms of the minimum space required, instead of just
using realloc() and let the underlying allocator decide what to do,
was doing an allocation + copy every time the minimum possible header
needed to represent the string was different than the current one.
This could be often a bit wasteful, because if we go, for instance, from
the 32 bit fields header to the 16 bit fields header, the overhead of
the header is normally very small. With this commit we call realloc
instead, unless the change in header size is very significant in relation
to the string length.
2017-11-03 10:19:27 +01:00
oranagra
66f03b8340 add SDS_NOINIT option to sdsnewlen to avoid unnecessary memsets.
this commit also contains small bugfix in rdbLoadLzfStringObject
a bug that currently has no implications.
2017-02-23 03:04:08 -08:00
antirez
1d0a16d239 sds: don't check for impossible string size in 32 bit systems. 2016-09-01 11:04:22 +02:00
oranagra
26e236b2a6 minor fixes - mainly signalModifiedKey, and GEORADIUS 2016-05-09 12:05:33 +03:00
antirez
e88759f742 Lua debugger: use sds_malloc() to allocate eval cli array.
Redis-cli handles the debugger "eval" command in a special way since
sdssplitargs() would not be ok: we need to send the Redis debugger the
whole Lua script without any parsing. However in order to later free the
argument vector inside redis-cli using just sdsfreesplitres(), we need
to allocate the array of SDS pointers using the same allocator SDS is
using, that may differ to what Redis is using.

So now a newer version of SDS exports sds_malloc() and other allocator
functions to give access, to the program it is linked to, the allocator
used internally by SDS.
2015-11-17 15:43:23 +01:00
antirez
b1e21f503d SDS: Copyright updated further. 2015-07-25 17:41:56 +02:00
antirez
92607da7a5 SDS: changes to unify Redis SDS with antirez/sds repo. 2015-07-25 17:25:44 +02:00
antirez
9d1bde4c49 SDS: Copyright notice updated. 2015-07-25 17:08:44 +02:00
antirez
16984057e5 SDS: sdsjoinsds() call ported from antirez/sds fork. 2015-07-25 17:05:20 +02:00
antirez
c8b31651e7 SDS: avoid compiler warning in sdsIncrLen(). 2015-07-24 09:39:12 +02:00
antirez
e80ee4d3db SDS: use type 8 if we are likely to append to the string.
When empty strings are created, or when sdsMakeRoomFor() is called, we
are likely into an appending pattern. Use at least type 8 SDS strings
since TYPE 5 does not remember the free allocation size and requires to
call sdsMakeRoomFor() at every new piece appended.
2015-07-23 16:10:08 +02:00
antirez
0fb9a81301 Fix SDS type 5 sdsIncrLen() bug and added test.
Thanks to @oranagra for spotting this error.
2015-07-20 16:18:08 +02:00
antirez
c7b7769356 SDS: New sds type 5 implemented.
This is an attempt to use the refcount feature of the sds.c fork
provided in the Pull Request #2509. A new type, SDS_TYPE_5 is introduced
having a one byte header with just the string length, without
information about the available additional length at the end of the
string (this means that sdsMakeRoomFor() will be required each time
we want to append something, since the string will always report to have
0 bytes available).

More work needed in order to avoid common SDS functions will pay the
cost of this type. For example both sdscatprintf() and sdscatfmt()
should try to upgrade to SDS_TYPE_8 ASAP when appending chars.
2015-07-15 12:24:49 +02:00
Oran Agra
c498bcbc7f sds size classes - memory optimization 2015-07-14 17:17:06 +02:00
FuGangqiang
a67aedb738 sdsfree x and y 2015-04-20 23:03:34 +08:00
FuGangqiang
7a92c11797 fix doc example 2015-04-20 21:46:48 +08:00
FuGangqiang
4e5b058ed0 fix typo 2015-04-19 23:42:27 +08:00
antirez
28e8878baa sdsnative() removed: New rdb.c API can load native strings. 2015-01-08 09:52:44 +01:00
Matt Stancliff
2133073bb8 Add sdsnative()
Use the existing memory space for an SDS to convert it to a regular
character buffer so we don't need to allocate duplicate space just
to extract a usable buffer for native operations.
2015-01-02 11:16:08 -05:00
Matt Stancliff
d2356d1ce7 Allow all code tests to run using Redis args
Previously, many files had individual main() functions for testing,
but each required being compiled with their own testing flags.
That gets difficult when you have 8 different flags you need
to set just to run all tests (plus, some test files required
other files to be compiled aaginst them, and it seems some didn't
build at all without including the rest of Redis).

Now all individual test main() funcions are renamed to a test
function for the file itself and one global REDIS_TEST define enables
testing across the entire codebase.

Tests can now be run with:
  - `./redis-server test <test>`

  e.g. ./redis-server test ziplist

If REDIS_TEST is not defined, then no tests get included and no
tests are included in the final redis-server binary.
2014-12-23 09:31:03 -05:00
antirez
070ec599ba sdsformatip() removed.
Specialized single-use function. Not the best match for sds.c btw.
Also genClientPeerId() is no longer static: we need symbols.
2014-12-11 18:29:04 +01:00
Matt Stancliff
89d35a3391 Add centralized IP/Peer formatting functions
This stops us from needing to manually check against ":" to
add brackets around IPv6 addresses everywhere.
2014-12-11 10:05:35 -05:00
antirez
b06903493f Merge branch 'unstable' of github.com:/antirez/redis into unstable 2014-12-10 09:51:00 +01:00
antirez
1a5d6bf9f8 sds.c: more tests for sdstrim(). 2014-12-10 09:48:56 +01:00
Brochen
3b452712ea Update sds.c
in the case (all chars of the string s found in 'cset' ),
line[573] will no more do the same thing line[572] did.
this will be more faster especially in the case that the string s is very long and all chars of string s found in 'cset'
2014-12-10 11:19:13 +08:00
Sun He
22230af4c9 sds.c: Correct two spelling mistakes in comments 2014-11-03 17:21:54 +08:00
Sun He
feee9c753a sds.c/sdscatvprintf: set va_end to finish va_list cpy 2014-11-02 10:42:26 +08:00
Sun He
d9ae8b358b sds.c: Correct some comments 2014-11-02 10:40:28 +08:00
Ted Nyman
b1fd6d35c6 Fix on-place -> in-place
Closes #1373
2014-09-29 06:49:07 -04:00
Lynn
b984044c0c Remove surplus double quotes
Closes #1877
2014-09-29 06:49:05 -04:00
antirez
5e780be2ad No longer useful assert removed from sdsIncrLen(). 2014-08-25 10:36:26 +02:00
antirez
02b06ba8f0 Use unsigned integers in SDS header.
This raises the max string to 4GB without any downside.
2014-08-13 10:53:51 +02:00
Pieter Noordhuis
de398a534e va_copy must be matched by va_end
Hat tip to @rfuchs. See: https://github.com/redis/hiredis/pull/178.

Fixes #1187
2014-08-12 11:50:02 +02:00
antirez
1c94889182 No more trailing spaces in Redis source code. 2014-06-26 18:48:40 +02:00
antirez
82d95f85f8 Silence different signs comparison warning in sds.c. 2014-06-23 11:50:24 +02:00
antirez
de11c325ae Added new sdscatfmt() %u and %U format specifiers.
This commit also fixes a bug in the implementation of sdscatfmt()
resulting from stale references to the SDS string header after
sdsMakeRoomFor() calls.
2014-04-28 16:38:17 +02:00
antirez
8e7e7cc5eb sdscatfmt() added to SDS library.
sdscatprintf() relies on printf() family libc functions and is sometimes
too slow in critical code paths. sdscatfmt() is an alternative which is:

1) Far less capable.
2) Format specifier uncompatible.
3) Faster.

It is suitable to be used in those speed critical code paths such as
CLIENT LIST output generation.
2014-04-28 16:23:17 +02:00
antirez
e2c6bb0a2a sdscatvprintf(): Try to use a static buffer.
For small content the function now tries to use a static buffer to avoid
a malloc/free cycle that is too costly when the function is used in the
context of performance critical code path such as INFO output generation.

This change was verified to have positive effects in the execution speed
of the INFO command.
2014-03-24 10:20:33 +01:00
antirez
57e4d0ca6b sdscatvprintf(): guess buflen using format length.
sdscatvprintf() uses a loop where it tries to output the formatted
string in a buffer of the initial length, if there was not enough room,
a buffer of doubled size is tried and so forth.

The initial guess for the buffer length was very poor, an hardcoded
"16". This caused the printf to be processed multiple times without a
good reason. Given that printf functions are already not fast, the
overhead was significant.

The new heuristic is to use a buffer 4 times the length of the format
buffer, and 32 as minimal size. This appears to be a good balance for
typical uses of the function inside the Redis code base.

This change improved INFO command performances 3 times.
2014-03-24 09:44:11 +01:00
codeeply
45637a3a82 comment mistake fixed 2013-12-12 16:33:29 +08:00