zone_writer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef MEM_ZONE_WRITER_H
  15. #define MEM_ZONE_WRITER_H
  16. #include <datasrc/memory/load_action.h>
  17. #include <boost/noncopyable.hpp>
  18. #include <dns/dns_fwd.h>
  19. namespace isc {
  20. namespace datasrc {
  21. namespace memory {
  22. class ZoneTableSegment;
  23. /// \brief Does an update to a zone.
  24. ///
  25. /// This represents the work of a (re)load of a zone. The work is divided
  26. /// into three stages -- load(), install() and cleanup(). They should
  27. /// be called in this order for the effect to take place.
  28. ///
  29. /// We divide them so the update of zone data can be done asynchronously,
  30. /// in a different thread. The install() operation is the only one that needs
  31. /// to be done in a critical section.
  32. ///
  33. /// This class provides strong exception guarantee for each public
  34. /// method. That is, when any of the methods throws, the entire state
  35. /// stays the same as before the call.
  36. class ZoneWriter : boost::noncopyable {
  37. public:
  38. /// \brief Constructor
  39. ///
  40. /// \throw isc::InvalidOperation if \c segment is read-only.
  41. ///
  42. /// \param segment The zone table segment to store the zone into.
  43. /// \param load_action The callback used to load data.
  44. /// \param name The name of the zone.
  45. /// \param rrclass The class of the zone.
  46. ZoneWriter(ZoneTableSegment& segment,
  47. const LoadAction& load_action, const dns::Name& name,
  48. const dns::RRClass& rrclass);
  49. /// \brief Destructor.
  50. ~ZoneWriter();
  51. /// \brief Get the zone data into memory.
  52. ///
  53. /// This is the part that does the time-consuming loading into the memory.
  54. /// This can be run in a separate thread, for example. It has no effect on
  55. /// the data actually served, it only prepares them for future use.
  56. ///
  57. /// This is the first method you should call on the object. Never call it
  58. /// multiple times.
  59. ///
  60. /// \note As this contains reading of files or other data sources, or with
  61. /// some other source of the data to load, it may throw quite anything.
  62. /// If it throws, do not call any other methods on the object and
  63. /// discard it.
  64. /// \note After successful load(), you have to call cleanup() some time
  65. /// later.
  66. /// \throw isc::InvalidOperation if called second time.
  67. void load();
  68. /// \brief Put the changes to effect.
  69. ///
  70. /// This replaces the old version of zone with the one previously prepared
  71. /// by load(). It takes ownership of the old zone data, if any.
  72. ///
  73. /// You may call it only after successful load() and at most once.
  74. ///
  75. /// The operation is expected to be fast and is meant to be used inside
  76. /// a critical section.
  77. ///
  78. /// This may throw in rare cases. If it throws, you still need to
  79. /// call cleanup().
  80. ///
  81. /// \throw isc::InvalidOperation if called without previous load() or for
  82. /// the second time or cleanup() was called already.
  83. void install();
  84. /// \brief Clean up resources.
  85. ///
  86. /// This releases all resources held by owned zone data. That means the
  87. /// one loaded by load() in case install() was not called or was not
  88. /// successful, or the one replaced in install().
  89. ///
  90. /// \throw none
  91. void cleanup();
  92. private:
  93. // We hide details as this class will be used by various applications
  94. // and we use some internal data structures in the implementation.
  95. struct Impl;
  96. Impl* impl_;
  97. };
  98. }
  99. }
  100. }
  101. #endif