1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
Commit Graph

42 Commits

Author SHA1 Message Date
Amitay Isaacs
04a061e4d1 ctdb-io: Do not use sys_write to write to client sockets
When sending messages to clients, ctdb checks for EAGAIN error code and
schedules next write in the subsequent event loop.  Using sys_write in
these places causes ctdb to loop hard till a client is able to read from
the socket.  With real time scheduling, ctdb daemon spins consuming 100%
of CPU trying to write to the client sockets.  This can be quite harmful
when running under VMs or machines with single CPU.

This regression was introduced when all read/write calls were replaced to
use sys_read/sys_write wrappers (c1558adeaa).

The existing code backs off in case of EAGAIN failures and waits for an
event loop to process the write again.  This should give ctdb clients
a chance to get scheduled and to process the ctdb socket.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>

Autobuild-User(master): Martin Schwenke <martins@samba.org>
Autobuild-Date(master): Tue Feb 24 12:29:30 CET 2015 on sn-devel-104
2015-02-24 12:29:30 +01:00
Martin Schwenke
c1558adeaa ctdb: Use sys_read() and sys_write() to ensure correct signal interaction
... and avoid compiler warnings in some cases.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2014-08-21 04:46:13 +02:00
Volker Lendecke
478ef9493f ctdb: Fix verbose_memory_names
If we have already partly written a packet, "data" and thus "pkt->data"
does not point to the start of the packet anymore. Assign "hdr" while
it still points at the start of the header.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>

Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Tue Jul 22 06:09:50 CEST 2014 on sn-devel-104
2014-07-22 06:09:50 +02:00
Volker Lendecke
70c79f5140 ctdb: Avoid a talloc in ctdb_queue_send
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2014-07-22 03:42:13 +02:00
Amitay Isaacs
a61a4b1254 common/io: Limit the queue buffer size for fair scheduling via tevent
If we process all the data available in a socket buffer, CTDB can stay busy
processing lots of packets via immediate event mechanism in tevent.  After
processing an immediate event, tevent returns without epoll_wait.  So as long
as there are immediate events, tevent will never poll other FDs.  CTDB will
report this as "Event handling took xx seconds" warning.  This is misleading
since CTDB is very busy processing packets, but never gets to the point of
polling FDs.

The improvement in socket handling made it worse when handling traverse
control.  There were lots of packets filled in the socket buffer quickly and
CTDB stayed busy processing those packets and not polling other FDs and timer
events.  This can lead to controls timing out and in worse case other nodes
marking busy node as disconnected.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>

(This used to be ctdb commit 92939c1178d04116d842708bc2d6a9c2950e36cc)
2013-08-22 14:08:52 +10:00
Amitay Isaacs
cfb7f74fa2 Revert "common/io: Keep queue buffer size multiple of 4K"
This reverts commit 5e9b1a7e24d058ff88aaa0563db36a804e866fa9.

This is not the best approach.  Allowing queue buffer size to grow
indefinitely causes large number of CTDB packets to be queued up very
quickly which when processed via immediate events will block CTDB from
processing events from other FDs.  If there are immediate events queued
up, tevent will never process any of the FDs till all immediate events
are processed.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>

(This used to be ctdb commit d8b094e804efc53fae9f44c6ef961b7b5797d290)
2013-08-22 14:08:52 +10:00
Amitay Isaacs
d349b56e2d common/io: Keep queue buffer size multiple of 4K
Currently queue buffer size is realloc'd every time we need to extend the
buffer.  Small increments can cause memory fragmentation.  Instead always
extend buffer in multiples of 4K.  This should reduce multiple talloc_realloc
calls when there are lots of packets in the socket buffer.

Also, if queue buffer has grown larger than 64K, throw away the buffer once
all the requests in the queue have been processed.  That way queue does not
hold on to large buffers.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>

(This used to be ctdb commit 5e9b1a7e24d058ff88aaa0563db36a804e866fa9)
2013-08-09 11:07:37 +10:00
Mathieu Parent
d82b9ae410 build: Fix tdb.h path to enable building with system TDB library
(This used to be ctdb commit f8bf99de3a5f56be67aaa67ed836458b1cf73e86)
2013-06-14 16:45:27 +10:00
Amitay Isaacs
d4407a6516 common/io: For scheduling immediate events use tevent_schedule_immediate
tevent_schedule_immediate() is much more efficient at handling events that need
to be processed immediately rather than creating timed events with
timeval_zero().

Signed-off-by: Amitay Isaacs <amitay@gmail.com>

(This used to be ctdb commit 11734be353a1e246163eda631d35dfe55d1d6fb1)
2013-03-06 15:32:37 +11:00
Amitay Isaacs
a2abdc1353 common/io: Rewrite socket handling code to read all available data
This improves the processing of packets considerably.  It has been
observed that there can be as many as 10 packets in the socket buffer and
the current code of reading a single packet from a socket at a time is
not very optimal.  This change reads all the bytes from socket buffer and
then parses to extract multiple packets.  If there are multiple packets,
set up a timed event to process next packet.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>

(This used to be ctdb commit d788bc8f7212b7dc1587ae592242dc8c876f4053)
2013-02-19 17:18:21 +11:00
Amitay Isaacs
4392591555 Remove explicit include of lib/tevent/tevent.h.
Signed-off-by: Amitay Isaacs <amitay@gmail.com>

(This used to be ctdb commit 0681014ca5ed2a9b56f63fdace7f894beccf8a9a)
2012-04-13 17:28:14 +10:00
Ronnie Sahlberg
b5b4c1a2ea explain why we use FIONREAD
(This used to be ctdb commit d0f85478c37828eb8a24315d4326eb4eaedb9afc)
2012-01-04 21:41:12 +11:00
Martin Schwenke
c8286b8dc7 Clean up warnings: remove unused function dump_packet()
Signed-off-by: Martin Schwenke <martin@meltin.net>

(This used to be ctdb commit c22e201be15e7d5b788c2f5f7916b553e0faaa2a)
2011-11-09 15:47:30 +11:00
David Disseldorp
e097b7f8ff io: Make queue_io_read() safe for reentry
queue_io_read() may be reentered via the queue callback, recoverd is
particularly guilty of this.

queue_io_read() is not safe for reentry if more than one packet is
received and partial chunks follow - data read off the pipe on re-entry
is assumed to be the start-of-packet four byte length. This leads to a
wrongly aligned stream and the notorious "Invalid packet of length 0"
errors.

This change fixes queue_io_read() to be safe under reentry, only a
single packet is processed per call.

https://bugzilla.samba.org/show_bug.cgi?id=8319

(This used to be ctdb commit 9ea41d2fab612772f861270c8a59c01c43bd3a4c)
2011-08-05 14:27:18 +10:00
Rusty Russell
f93440c4b7 event: Update events to latest Samba version 0.9.8
In Samba this is now called "tevent", and while we use the backwards
compatibility wrappers they don't offer EVENT_FD_AUTOCLOSE: that is now
a separate tevent_fd_set_auto_close() function.

This is based on Samba version 7f29f817fa.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 85e5e760cc91eb3157d3a88996ce474491646726)
2010-08-18 09:16:31 +09:30
Rusty Russell
7061ceffd8 Report client for queue errors.
We've been seeing "Invalid packet of length 0" errors, but we don't know
what is sending them.  Add a name for each queue, and print nread.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit e6cf0e8f14f4263fbd8b995418909199924827e9)
2010-07-01 23:08:49 +10:00
Rusty Russell
d5f6026a22 libctdb: reorganize headers: remove ctdb.h, add ctdb_client.h and ctdb_protocol.h
ctdb_client.h is the existing internal client interface (which was mainly
in ctdb.h), and ctdb_protocol.h is the information needed for the wire
protocol only.

ctdb.h will be the new, shiny, libctdb API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

(This used to be ctdb commit 4bba6b8cd47b352f98d41f9f06258d5ac3c9adef)
2010-05-20 15:18:30 +09:30
Andrew Tridgell
2406733ed2 ctdb: migrate to new dlinklist.h from Samba
(This used to be ctdb commit f63c091f12f8d582e9518673365c7c52479c470c)
2010-02-09 09:20:55 +11:00
Andrew Tridgell
3eb9735be5 ctdb: move ctdb_io.c to use TLIST_*() macros
This will make large packet queues much more efficient

(This used to be ctdb commit e3f198056230073135ea6354bbef30c5bb022f8f)
2010-02-04 15:37:53 +11:00
Ronnie Sahlberg
a2857b1504 We only queued up to 1000 packets per queue before we start dropping
packets, to avoid the queue to grow excessively if smbd has blocked.

This could cause traverse packets to become discarded in case the main
smbd daemon does a traverse of a database while there is a recovery
(sending a erconfigured message to smbd, causing an avalanche of unlock
messages to be sent across the cluster.)

This avalance of messages could cause also the tranversal message to be
discarded  causing the main smbd process to hang indefinitely waiting
for the traversal message that will never arrive.

Bump the maximum queue length before starting to discard messages from
1000 to 1000000 and at the same time rework the queueing slightly so we
can append messages cheaply to the queue instead of walking the list
from head to tail every time.

(This used to be ctdb commit 59ba5d7f80e0465e5076533374fb9ee862ed7bb6)
2010-02-04 09:54:06 +11:00
Rusty Russell
9e84872ecd ctdb_io: fix use-after-free on invalid packets
Wolfgang saw a talloc complaint about using freed memory in ctdb_tcp_read_cb.
His fix was to remove the talloc_free() in that function, which causes
loops when a socket is closed (as it does not get removed from the event
system), eg:
	netcat 192.168.1.2 4379 < /dev/null

The real bug is that when we have more than one pending packet in the
queue, we loop calling the callback without any safeguards should that
callback free the queue (as it tends to do on invalid packets).  This
can be reproduced by sending more than one bogus packet at once:
	# Length word at start: 4 == empty packet (assumed little endian)
	/usr/bin/printf \\4\\0\\0\\0\\4\\0\\0\\0 > /tmp/pkt
	netcat 192.168.1.2 4379 < /tmp/pkt

Using a destructor we can check if the callback frees us, and exit
immediately.  Elsewhere, we return after the callback anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

(This used to be ctdb commit 4d0523dd94fb07e860b3e8118691f93d1ef8d0fa)
2009-12-02 11:27:23 +11:00
Ronnie Sahlberg
8aacfa348d Suggestion from Volker,
make ctdb_queue_length() cheaper by using a counter variable instead of counting the number of packets each time.

(This used to be ctdb commit 331c6e3afd96d8b5e191153a631efdbdabb6ea33)
2009-10-26 12:20:52 +11:00
Ronnie Sahlberg
9b8c72c446 When clients have blocked, perhaps because the node is banned or stopped and the client is blocked trying to tdb_fetch() a record, make sure we dont queue up too many REQ_MESSAGES.
Add a new tunable to control the maximum queue size we allow to a blocked client before we start discarding REQ_MESSAGES instead of queueing them for delivery.

    This avoids having queued up very very large number of MESSAGES that samba semds
     between eachother to nodes that are blocked/banned/stopped for extended periods
    .

(This used to be ctdb commit f76d6fed8f9630450263b9fa4b5fdf3493fb1e11)
2009-10-21 15:20:55 +11:00
Ronnie Sahlberg
27a7f854f5 add improvements to tracking memory usage in ctdbd adn the recovery daemon
and a ctdb command to pull the talloc memory map from a recovery daemon
ctdb rddumpmemory

(This used to be ctdb commit d23950be7406cf288f48b660c0f57a9b8d7bdd05)
2008-04-01 15:34:54 +11:00
Ronnie Sahlberg
78081de82a from tridge: decorate dumpmemory output so that packets that are queued show up with a little more information to make memory leak debugging easier
(This used to be ctdb commit 890832ba37d92c7996b38735451f93592c37ff79)
2008-04-01 11:31:42 +11:00
Andrew Tridgell
f6e53f433b merge from ronnie
(This used to be ctdb commit e7b57d38cf7255be823a223cf15b7526285b4f1c)
2008-02-04 20:07:15 +11:00
Andrew Tridgell
32de198fd3 update lib/replace from samba4
(This used to be ctdb commit f0555484105668c01c21f56322992e752e831109)
2007-07-10 15:29:31 +10:00
Andrew Tridgell
bf3b740a1b ctdb is GPL not LGPL
(This used to be ctdb commit 8624378010d1c2a1438e1e701339dfba7276f960)
2007-05-31 13:50:53 +10:00
Andrew Tridgell
1140d5a20a fixed more warnings on 64 bit boxes
(This used to be ctdb commit 2f6eae476203f8a8b28e083553204c01f224c8a5)
2007-05-29 13:58:41 +10:00
Andrew Tridgell
dcd23d47a7 another place where we could send a partial packet
(This used to be ctdb commit 4e0c57718a0c9f51b5b2e02bbf516c63c5be0a35)
2007-05-28 08:37:54 +10:00
Andrew Tridgell
35955c1476 drop any partialialy send packets when we get a socket write error
(This used to be ctdb commit 4f7b97af8e0075de56059fffc57a86cb0c16df46)
2007-05-26 16:41:32 +10:00
Andrew Tridgell
2b86216b66 handle corrupt ctdb packets better
(This used to be ctdb commit aea4d78645a99eb22860048350b5f20841c17704)
2007-05-26 14:46:12 +10:00
Andrew Tridgell
527b2352ac fixed two more places where we don't correctly handle write errors on sockets
(This used to be ctdb commit f4a71bb63e7f75d21b66f9eaeac997c2029cd146)
2007-05-15 14:08:58 +10:00
Andrew Tridgell
542b76136e - take advantage of the new EVENT_FD_AUTOCLOSE flag
- use the tdb_chainlock_mark() call to allow us to guarantee forward progress in the ctdb_lockwait code

(This used to be ctdb commit e201e98aad0fef6a779a80f3b1ae7792953e2d6b)
2007-05-05 17:19:59 +10:00
Andrew Tridgell
472b96d6d3 first stage of efficient non-blocking ctdb traverse
(This used to be ctdb commit 4c23e6f26bde421bb56b55de9d6cd3e319b2be40)
2007-05-03 12:16:03 +10:00
Andrew Tridgell
e21f69107f yay! finally fixed the bug that volker, ronnie and I have been chasing
for 2 days.

The main bug was in smbd, but there was a secondary (and more subtle)
bug in ctdb that the bug in smbd exposed. When we get send a dmaster
reply, we have to correctly update the dmaster in the recipient even
if the original requst has timed out, otherwise ctdbd can get into a
loop fighting over who will handle a key.

This patch also cleans up the packet allocation, and makes ctdbd
become a real daemon.

(This used to be ctdb commit 59405e59ef522b97d8e20e4b14310a217141ac7c)
2007-04-29 16:19:40 +02:00
Andrew Tridgell
34bf25e227 - fix includes to work in both samba4 and ctdb standalone
- when we do a store_unlock the lock record becomes unlocked, so we
  must destroy it (or we leak memory)

(This used to be ctdb commit d85955640e670dd580073da96b25fb8a10c08d18)
2007-04-16 10:21:44 +10:00
Andrew Tridgell
65cdf2297a private -> private_data for samba3
(This used to be ctdb commit 080b6901173afb2ad618dd0621876ff478c7d6e5)
2007-04-13 20:38:24 +10:00
Andrew Tridgell
82e4ccbf3e merge from ronnie
(This used to be ctdb commit 886a3e9122168ececc257aa1bef2f5de2f2d8d7e)
2007-04-10 19:35:21 +10:00
Andrew Tridgell
f1e0174e83 made all sockets handle partial IO
abstract IO via ctdb_queue_*() functions

(This used to be ctdb commit 636ae76f4632b29231db87be32c9114f58b37840)
2007-04-10 19:33:21 +10:00
Ronnie sahlberg
9ba0f9db6f remove old ifdef that remained from when this was a header file
(This used to be ctdb commit 050f302103b32ea3895fc97dae7726f11fbf01e3)
2007-04-10 14:53:23 +10:00
Ronnie sahlberg
190b97f0ed make normal/deamon mode controllable by a ctdb flag so that the api looks the same in both modes to a client.
send the correct structure back to a client

assorted other cleanups

(tests/test1.sh now works in daemon mode)

(This used to be ctdb commit f4593754cab750dfdb9384884502e2e1b8fde1f0)
2007-04-10 06:03:39 +10:00