~drizzle-trunk/drizzle/development

1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
1
/*
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
2
 * Copyright (C) 2010 Joseph Daly <skinny.moey@gmail.com>
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *   * Redistributions of source code must retain the above copyright notice,
9
 *     this list of conditions and the following disclaimer.
10
 *   * Redistributions in binary form must reproduce the above copyright notice,
11
 *     this list of conditions and the following disclaimer in the documentation
12
 *     and/or other materials provided with the distribution.
13
 *   * Neither the name of Joseph Daly nor the names of its contributors
14
 *     may be used to endorse or promote products derived from this software
15
 *     without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27
 * THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 */
30
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
31
#pragma once
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
32
33
#include "scoreboard_slot.h"
1683.1.1 by Joe Daly
use boost for locking instead of pthread
34
#include <boost/thread/shared_mutex.hpp>
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
35
36
#include <vector>
37
38
class Scoreboard
39
{
40
public:
41
  Scoreboard(uint32_t in_number_sessions, uint32_t in_number_buckets);
42
43
  ~Scoreboard();
44
1320.5.13 by Joe Daly
add description and comments to various files
45
  /**
46
   * Locates a ScoreboardSlot that is not in use, marks the slot
47
   * as being used and returns a pointer to it. The caller can
48
   * update individual statistics via the pointer without having
49
   * to lock or worry about concurrent updates.  
50
   * 
51
   * @param Pointer to the session 
52
   * @return Pointer to the ScoreboardSlot whose individual statistics 
1320.5.17 by Joe Daly
clean up some unneeded destructors and add update comments
53
   *   can be updated
1320.5.13 by Joe Daly
add description and comments to various files
54
   */
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
55
  ScoreboardSlot* findScoreboardSlotToLog(drizzled::Session *session);
56
1320.5.13 by Joe Daly
add description and comments to various files
57
  /**
1561.3.2 by Joe Daly
add session_status_new
58
   * Finds the ScoreboardSlot for a given session. This function differs
59
   * from findAndResetScoreboardSlot() as it returns the actual pointer
60
   * rather then a copy. Its possible that values could be changed in 
61
   * the underlying status variables, callers should beware. 
62
   */
63
  ScoreboardSlot* findOurScoreboardSlot(drizzled::Session *session);
64
2318.8.8 by Olaf van der Spek
Refactor Scoreboard
65
  uint32_t getBucketNumber(drizzled::Session*) const;
1491.4.6 by Joe Daly
rework stats_schema use static char * for command strings
66
2318.8.8 by Olaf van der Spek
Refactor Scoreboard
67
  uint32_t getNumberBuckets() const
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
68
  {
69
    return number_buckets;
70
  }
71
2318.8.8 by Olaf van der Spek
Refactor Scoreboard
72
  uint32_t getNumberPerBucket() const
1711.7.2 by Joseph Daly
add memory usage
73
  {
74
    return number_per_bucket;
75
  }
76
2318.8.8 by Olaf van der Spek
Refactor Scoreboard
77
  uint64_t getScoreboardSizeBytes() const
1711.7.1 by Joseph Daly
merge trunk
78
  {
79
    return scoreboard_size_bytes;
80
  } 
81
1683.1.1 by Joe Daly
use boost for locking instead of pthread
82
  std::vector<boost::shared_mutex* >* getVectorOfScoreboardLocks()
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
83
  {
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
84
    return &vector_of_scoreboard_locks;
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
85
  }
86
87
  std::vector<std::vector<ScoreboardSlot* >* >* getVectorOfScoreboardVectors()
88
  {
1320.5.7 by Joe Daly
get tests to work, need to fix read lock on stats_schema current commands
89
    return &vector_of_scoreboard_vectors; 
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
90
  }
91
92
private:
93
  uint32_t number_sessions;
1711.7.2 by Joseph Daly
add memory usage
94
  uint32_t number_per_bucket;
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
95
  uint32_t number_buckets;
1711.7.1 by Joseph Daly
merge trunk
96
  uint64_t scoreboard_size_bytes;
2318.8.8 by Olaf van der Spek
Refactor Scoreboard
97
  std::vector<std::vector<ScoreboardSlot*>*> vector_of_scoreboard_vectors;
98
  std::vector<boost::shared_mutex*> vector_of_scoreboard_locks;
1491.4.15 by Joe Daly
remove com_stat_vars and rework lock in scoreboard to not lock on Sessions locating a slot they previously owned
99
1561.3.2 by Joe Daly
add session_status_new
100
  ScoreboardSlot* claimOpenScoreboardSlot(drizzled::Session *session); 
1320.5.6 by Joe Daly
first pass at using a module vector approach of scoreboard
101
};
102