filesystem.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef LIBHDFSPP_LIB_FS_FILESYSTEM_H_
  19. #define LIBHDFSPP_LIB_FS_FILESYSTEM_H_
  20. #include "common/hdfs_public_api.h"
  21. #include "libhdfspp/hdfs.h"
  22. #include "rpc/rpc_engine.h"
  23. #include "ClientNamenodeProtocol.pb.h"
  24. #include "ClientNamenodeProtocol.hrpc.inl"
  25. namespace hdfs {
  26. class FileSystemImpl : public FileSystem {
  27. public:
  28. FileSystemImpl(IoService *io_service, const Options &options);
  29. void Connect(const std::string &server, const std::string &service,
  30. std::function<void(const Status &)> &&handler);
  31. virtual void Open(const std::string &path,
  32. const std::function<void(const Status &, InputStream *)>
  33. &handler) override;
  34. RpcEngine &rpc_engine() { return engine_; }
  35. private:
  36. IoServiceImpl *io_service_;
  37. RpcEngine engine_;
  38. ClientNamenodeProtocol namenode_;
  39. };
  40. class InputStreamImpl : public InputStream {
  41. public:
  42. InputStreamImpl(FileSystemImpl *fs,
  43. const ::hadoop::hdfs::LocatedBlocksProto *blocks);
  44. virtual void
  45. PositionRead(void *buf, size_t nbyte, uint64_t offset,
  46. const std::set<std::string> &excluded_datanodes,
  47. const std::function<void(const Status &, const std::string &,
  48. size_t)> &handler) override;
  49. template <class MutableBufferSequence, class Handler>
  50. void AsyncPreadSome(size_t offset, const MutableBufferSequence &buffers,
  51. const std::set<std::string> &excluded_datanodes,
  52. const Handler &handler);
  53. template <class BlockReaderTrait, class MutableBufferSequence, class Handler>
  54. void AsyncReadBlock(const std::string &client_name,
  55. const hadoop::hdfs::LocatedBlockProto &block,
  56. const hadoop::hdfs::DatanodeInfoProto &dn, size_t offset,
  57. const MutableBufferSequence &buffers,
  58. const Handler &handler);
  59. private:
  60. FileSystemImpl *fs_;
  61. unsigned long long file_length_;
  62. std::vector<::hadoop::hdfs::LocatedBlockProto> blocks_;
  63. template <class Reader> struct HandshakeContinuation;
  64. template <class Reader, class MutableBufferSequence>
  65. struct ReadBlockContinuation;
  66. struct RemoteBlockReaderTrait;
  67. };
  68. }
  69. #include "inputstream_impl.h"
  70. #endif