summaryrefslogtreecommitdiff
path: root/src/networking.c
Commit message (Collapse)AuthorAgeFilesLines
* CLIENT LIST speedup via peerid caching + smart allocation.antirez2014-04-281-19/+31
| | | | | | | | This commit adds peer ID caching in the client structure plus an API change and the use of sdsMakeRoomFor() in order to improve the reallocation pattern to generate the CLIENT LIST output. Both the changes account for a very significant speedup.
* Use sdscatfmt() in getClientInfoString() to make it faster.antirez2014-04-281-9/+9
|
* Process events with processEventsWhileBlocked() when blocked.antirez2014-04-281-0/+23
| | | | | | | | When we are blocked and a few events a processed from time to time, it is smarter to call the event handler a few times in order to handle the accept, read, write, close cycle of a client in a single pass, otherwise there is too much latency added for clients to receive a reply while the server is busy in some way (for example during the DB loading).
* Accept multiple clients per iteration.antirez2014-04-281-15/+23
| | | | | | | | | | | | | | When the listening sockets readable event is fired, we have the chance to accept multiple clients instead of accepting a single one. This makes Redis more responsive when there is a mass-connect event (for example after the server startup), and in workloads where a connect-disconnect pattern is used often, so that multiple clients are waiting to be accepted continuously. As a side effect, this commit makes the LOADING, BUSY, and similar errors much faster to deliver to the client, making Redis more responsive when there is to return errors to inform the clients that the server is blocked in an not interruptible operation.
* AE_ERR -> ANET_ERR in acceptUnixHandler().antirez2014-04-281-1/+1
| | | | No actual changes since the value is the same.
* Missing return REDIS_ERR added to processMultibulkBuffer().antirez2014-04-231-1/+3
| | | | | | | When we set a protocol error we should return with REDIS_ERR to let the caller know it should stop processing the client. Bug found in a code auditing related to issue #1699.
* Fix return value check for anetTcpAcceptMatt Stancliff2014-03-111-1/+1
| | | | | | | anetTcpAccept returns ANET_ERR, not AE_ERR. This isn't a physical error since both ANET_ERR and AE_ERR are -1, but better to be consistent.
* CLIENT PAUSE and related API implemented.antirez2014-02-041-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | The API is one of the bulding blocks of CLUSTER FAILOVER command that executes a manual failover in Redis Cluster. However exposed as a command that the user can call directly, it makes much simpler to upgrade a standalone Redis instance using a slave in a safer way. The commands works like that: CLIENT PAUSE <milliesconds> All the clients that are not slaves and not in MONITOR state are paused for the specified number of milliesconds. This means that slaves are normally served in the meantime. At the end of the specified amount of time all the clients are unblocked and will continue operations normally. This command has no effects on the population of the slow log, since clients are not blocked in the middle of operations but only when there is to process new data. Note that while the clients are unblocked, still new commands are accepted and queued in the client buffer, so clients will likely not block while writing to the server while the pause is active.
* Don't log MONITOR clients as disconnecting slaves.antirez2014-01-251-1/+1
|
* Cluster: support to read from slave nodes.antirez2014-01-141-0/+1
| | | | | | | | | | A client can enter a special cluster read-only mode using the READONLY command: if the client read from a slave instance after this command, for slots that are actually served by the instance's master, the queries will be processed without redirection, allowing clients to read from slaves (but without any kind fo read-after-write guarantee). The READWRITE command can be used in order to exit the readonly state.
* Log disconnection with slave only when ip:port is available.antirez2013-12-251-4/+4
|
* Slave disconnection is an event worth logging.antirez2013-12-221-0/+10
|
* Log when a slave lose the connection with its master.antirez2013-12-211-9/+10
|
* Merge pull request #1451 from yossigo/unbalanced-quotes-fixSalvatore Sanfilippo2013-12-111-0/+5
|\ | | | | Return proper error on requests with an unbalanced number of quotes.
| * Return proper error on requests with an unbalanced number of quotes.Yossi Gottlieb2013-12-081-0/+5
| |
* | Slaves heartbeat while loading RDB files.antirez2013-12-091-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Starting with Redis 2.8 masters are able to detect timed out slaves, while before 2.8 only slaves were able to detect a timed out master. Now that timeout detection is bi-directional the following problem happens as described "in the field" by issue #1449: 1) Master and slave setup with big dataset. 2) Slave performs the first synchronization, or a full sync after a failed partial resync. 3) Master sends the RDB payload to the slave. 4) Slave loads this payload. 5) Master detects the slave as timed out since does not receive back the REPLCONF ACK acknowledges. Here the problem is that the master has no way to know how much the slave will take to load the RDB file in memory. The obvious solution is to use a greater replication timeout setting, but this is a shame since for the 0.1% of operation time we are forced to use a timeout that is not what is suited for 99.9% of operation time. This commit tries to fix this problem with a solution that is a bit of an hack, but that modifies little of the replication internals, in order to be back ported to 2.8 safely. During the RDB loading time, we send the master newlines to avoid being sensed as timed out. This is the same that the master already does while saving the RDB file to still signal its presence to the slave. The single newline is used because: 1) It can't desync the protocol, as it is only transmitted all or nothing. 2) It can be safely sent while we don't have a client structure for the master or in similar situations just with write(2).
* | Handle inline requested terminated with just \n.antirez2013-12-091-1/+8
|/
* Fixed grammar: before H the article is a, not an.antirez2013-12-051-1/+1
|
* WAIT command: synchronous replication for Redis.antirez2013-12-041-0/+1
|
* BLPOP blocking code refactored to be generic & reusable.antirez2013-12-031-3/+5
|
* Removed old comments and dead code from freeClient().antirez2013-12-031-12/+14
|
* Grammar fix in freeClient().antirez2013-12-031-1/+1
|
* Replication: fix master timeout.antirez2013-10-041-1/+7
| | | | | | | | | | | Since we started sending REPLCONF ACK from slaves to masters, the lastinteraction field of the client structure is always refreshed as soon as there is room in the socket output buffer, so masters in timeout are detected with too much delay (the socket buffer takes a lot of time to be filled by small REPLCONF ACK <number> entries). This commit only counts data received as interactions with a master, solving the issue.
* Fix an hypothetical issue in processMultibulkBuffer().antirez2013-08-271-1/+5
|
* Don't over-allocate the sds string for large bulk requests.antirez2013-08-271-2/+2
| | | | | The call to sdsMakeRoomFor() did not accounted for the amount of data already present in the query buffer, resulting into over-allocation.
* Use precomptued objects for bulk and mbulk prefixes.antirez2013-08-121-2/+9
|
* Replication: better way to send a preamble before RDB payload.antirez2013-08-121-2/+4
| | | | | | | | | | | | | | | During the replication full resynchronization process, the RDB file is transfered from the master to the slave. However there is a short preamble to send, that is currently just the bulk payload length of the file in the usual Redis form $..length..<CR><LF>. This preamble used to be sent with a direct write call, assuming that there was alway room in the socket output buffer to hold the few bytes needed, however this does not scale in case we'll need to send more stuff, and is not very robust code in general. This commit introduces a more general mechanism to send a preamble up to 2GB in size (the max length of an sds string) in a non blocking way.
* sdsrange() does not need to return a value.antirez2013-07-241-5/+5
| | | | | | Actaully the string is modified in-place and a reallocation is never needed, so there is no need to return the new sds string pointer as return value of the function, that is now just "void".
* Inline protocol improved to accept quoted strings.antirez2013-07-241-2/+4
|
* getStringObjectSdsUsedMemory() function added.antirez2013-07-231-19/+17
| | | | | | | | | | Now that EMBSTR encoding exists we calculate the amount of memory used by the SDS part of a Redis String object in two different ways: 1) For raw string object, the size of the allocation is considered. 2) For embstr objects, the length of the string itself is used. The new function takes care of this logic.
* Fix setDeferredMultiBulkLength() c->reply_bytes handling with EMBSTRantirez2013-07-221-1/+4
| | | | | | | | This function missed proper handling of reply_bytes when gluing to the previous object was used. The issue was introduced with the EMBSTR new string object encoding. This fixes issue #1208.
* Fixed a possible bug in client->reply_bytes computation.antirez2013-07-221-0/+1
|
* Introduction of a new string encoding: EMBSTRantirez2013-07-221-9/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously two string encodings were used for string objects: 1) REDIS_ENCODING_RAW: a string object with obj->ptr pointing to an sds stirng. 2) REDIS_ENCODING_INT: a string object where the obj->ptr void pointer is casted to a long. This commit introduces a experimental new encoding called REDIS_ENCODING_EMBSTR that implements an object represented by an sds string that is not modifiable but allocated in the same memory chunk as the robj structure itself. The chunk looks like the following: +--------------+-----------+------------+--------+----+ | robj data... | robj->ptr | sds header | string | \0 | +--------------+-----+-----+------------+--------+----+ | ^ +-----------------------+ The robj->ptr points to the contiguous sds string data, so the object can be manipulated with the same functions used to manipulate plan string objects, however we need just on malloc and one free in order to allocate or release this kind of objects. Moreover it has better cache locality. This new allocation strategy should benefit both the memory usage and the performances. A performance gain between 60 and 70% was observed during micro-benchmarks, however there is more work to do to evaluate the performance impact and the memory usage behavior.
* addReplyDouble(): format infinite in a libc agnostic way.antirez2013-07-171-3/+10
| | | | | | | | There are systems that when printing +/- infinte with printf-family functions will not use the usual "inf" "-inf", but different strings. Handle that explicitly. Fixes issue #930.
* getClientPeerId() refactored into two functions.antirez2013-07-091-4/+12
|
* getClientPeerId() now reports errors.antirez2013-07-091-13/+13
| | | | We now also use it in CLIENT KILL implementation.
* getClientPeerID introduced.antirez2013-07-091-7/+34
| | | | | | | The function returns an unique identifier for the client, as ip:port for IPv4 and IPv6 clients, or as path:0 for Unix socket clients. See the top comment in the function for more info.
* All IP string repr buffers are now REDIS_IP_STR_LEN bytes.antirez2013-07-091-3/+2
|
* Mark places that might want changing for IPv6.Geoff Garside2013-07-081-0/+1
| | | | | | | | | | | | | | | | | | | | Any places which I feel might want to be updated to work differently with IPv6 have been marked with a comment starting "IPV6:". Currently the only comments address places where an IP address is combined with a port using the standard : separated form. These may want to be changed when printing IPv6 addresses to wrap the address in [] such as [2001:db8::c0:ffee]:6379 instead of 2001:db8::c0:ffee:6379 as the latter format is a technically valid IPv6 address and it is hard to distinguish the IPv6 address component from the port unless you know the port is supposed to be there.
* Expand ip char buffers which are too small for v6.Geoff Garside2013-07-081-2/+3
| | | | | Increase the size of character buffers being used to store printable IP addresses so that they can safely store IPv6 addresses.
* Mark ip string buffers which could be reduced.Geoff Garside2013-07-081-1/+1
| | | | | | | In two places buffers have been created with a size of 128 bytes which could be reduced to INET6_ADDRSTRLEN to still hold a full IP address. These places have been marked as they are presently big enough to handle the needs of storing a printable IPv6 address.
* Update anetTcpAccept & anetPeerToString calls.Geoff Garside2013-07-081-3/+3
| | | | | Add the additional ip buffer length argument to function calls of anetTcpAccept and anetPeerToString in network.c and cluster.c
* min-slaves-to-write: don't accept writes with less than N replicas.antirez2013-05-301-0/+1
| | | | | | This feature allows the user to specify the minimum number of connected replicas having a lag less or equal than the specified amount of seconds for writes to be accepted.
* Replication: send REPLCONF ACK to master.antirez2013-05-271-1/+2
|
* REPLCONF ACK command.antirez2013-05-271-0/+2
| | | | | | | | | | | | This special command is used by the slave to inform the master the amount of replication stream it currently consumed. it does not return anything so that we not need to consume additional bandwidth needed by the master to reply something. The master can do a number of things knowing the amount of stream processed, such as understanding the "lag" in bytes of the slave, verify if a given command was already processed by the slave, and so forth.
* Fixed a bug in no queueing replies to master.antirez2013-05-251-1/+2
|
* Replication: don't even queue replies to master commands.antirez2013-05-241-17/+7
| | | | | | | | | | | When master send commands, there is no need for the slave to reply. Redis used to queue the reply in the output buffer and discard the reply later, this is a waste of work and it is not clear why it was this way (I sincerely don't remember). This commit changes it in order to don't queue the reply at all. All tests passing.
* Top comment for prepareClientToWrite() clarified.antirez2013-05-241-2/+2
| | | | | We don't write the output buffer to the client socket for slaves only if the slave is not online.
* API to lookup commands with their original name.antirez2013-03-061-2/+2
| | | | | | | | | | | | | | | | A new server.orig_commands table was added to the server structure, this contains a copy of the commant table unaffected by rename-command statements in redis.conf. A new API lookupCommandOrOriginal() was added that checks both tables, new first, old later, so that rewriteClientCommandVector() and friends can lookup commands with their new or original name in order to fix the client->cmd pointer when the argument vector is renamed. This fixes the segfault of issue #986, but does not fix a wider range of problems resulting from renaming commands that actually operate on data and are registered into the AOF file or propagated to slaves... That is command renaming should be handled with care.
* Cluster: ASKING command fixed, state was not retained.antirez2013-02-201-2/+6
|