0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LocalBroker.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #include <Common/Compat.h>
23 
24 #include "LocalBroker.h"
25 
26 #include <Common/FileUtils.h>
27 #include <Common/Filesystem.h>
28 #include <Common/Path.h>
29 #include <Common/String.h>
30 #include <Common/System.h>
31 #include <Common/SystemInfo.h>
32 
34 
35 #include <cerrno>
36 #include <chrono>
37 #include <cstdio>
38 #include <cstring>
39 #include <string>
40 #include <thread>
41 #include <vector>
42 
43 extern "C" {
44 #include <dirent.h>
45 #include <fcntl.h>
46 #include <limits.h>
47 #if defined(__sun__)
48 #include <sys/fcntl.h>
49 #endif
50 #include <sys/stat.h>
51 #include <sys/types.h>
52 #include <sys/uio.h>
53 #include <unistd.h>
54 }
55 
56 using namespace Hypertable;
57 using namespace Hypertable::FsBroker;
58 using namespace std;
59 
60 atomic<int> LocalBroker::ms_next_fd {0};
61 
63  m_verbose = cfg->get_bool("verbose");
64  m_no_removal = cfg->get_bool("FsBroker.DisableFileRemoval");
65  if (cfg->has("DfsBroker.Local.DirectIO"))
66  m_directio = cfg->get_bool("DfsBroker.Local.DirectIO");
67  else
68  m_directio = cfg->get_bool("FsBroker.Local.DirectIO");
69 
70  m_metrics_handler = std::make_shared<MetricsHandler>(cfg, "local");
71  m_metrics_handler->start_collecting();
72 
73 #if defined(__linux__)
74  // disable direct i/o for kernels < 2.6
75  if (m_directio) {
76  if (System::os_info().version_major == 2 &&
78  m_directio = false;
79  }
80 #endif
81 
85  Path root;
86  if (cfg->has("DfsBroker.Local.Root"))
87  root = Path(cfg->get_str("DfsBroker.Local.Root"));
88  else
89  root = Path(cfg->get_str("root", ""));
90 
91  if (!root.is_complete()) {
92  Path data_dir = cfg->get_str("Hypertable.DataDirectory");
93  root = data_dir / root;
94  }
95 
96  m_rootdir = root.string();
97 
98  // ensure that root directory exists
99  if (!FileUtils::mkdirs(m_rootdir))
100  exit(EXIT_FAILURE);
101 }
102 
103 
104 
106  m_metrics_handler->stop_collecting();
107 }
108 
109 
110 void
112  uint32_t flags, uint32_t bufsz) {
113  int fd, local_fd;
114  String abspath;
115 
116  HT_DEBUGF("open file='%s' flags=%u bufsz=%d", fname, flags, bufsz);
117 
118  if (fname[0] == '/')
119  abspath = m_rootdir + fname;
120  else
121  abspath = m_rootdir + "/" + fname;
122 
123  fd = ++ms_next_fd;
124 
125  int oflags = O_RDONLY;
126 
127  if (m_directio && flags & Filesystem::OPEN_FLAG_DIRECTIO) {
128 #ifdef O_DIRECT
129  oflags |= O_DIRECT;
130 #endif
131  }
132 
136  if ((local_fd = ::open(abspath.c_str(), oflags)) == -1) {
137  report_error(cb);
138  HT_ERRORF("open failed: file='%s' - %s", abspath.c_str(), strerror(errno));
139  return;
140  }
141 
142 #if defined(__APPLE__)
143 #ifdef F_NOCACHE
144  //fcntl(local_fd, F_NOCACHE, 1);
145 #endif
146 #elif defined(__sun__)
147  if (m_directio)
148  directio(local_fd, DIRECTIO_ON);
149 #endif
150 
151  HT_INFOF("open( %s ) = %d (local=%d)", fname, (int)fd, local_fd);
152 
153  {
154  struct sockaddr_in addr;
155  OpenFileDataLocalPtr fdata(new OpenFileDataLocal(fname, local_fd, O_RDONLY));
156 
157  cb->get_address(addr);
158 
159  m_open_file_map.create(fd, addr, fdata);
160 
161  cb->response(fd);
162  }
163 }
164 
165 
166 void
167 LocalBroker::create(Response::Callback::Open *cb, const char *fname, uint32_t flags,
168  int32_t bufsz, int16_t replication, int64_t blksz) {
169  int fd, local_fd;
170  int oflags = O_WRONLY | O_CREAT;
171  String abspath;
172 
173  HT_DEBUGF("create file='%s' flags=%u bufsz=%d replication=%d blksz=%lld",
174  fname, flags, bufsz, (int)replication, (Lld)blksz);
175 
176  if (fname[0] == '/')
177  abspath = m_rootdir + fname;
178  else
179  abspath = m_rootdir + "/" + fname;
180 
181  fd = ++ms_next_fd;
182 
184  oflags |= O_TRUNC;
185  else
186  oflags |= O_APPEND;
187 
188  if (m_directio && flags & Filesystem::OPEN_FLAG_DIRECTIO) {
189 #ifdef O_DIRECT
190  oflags |= O_DIRECT;
191 #endif
192  }
193 
197  if ((local_fd = ::open(abspath.c_str(), oflags, 0644)) == -1) {
198  report_error(cb);
199  HT_ERRORF("open failed: file='%s' - %s", abspath.c_str(), strerror(errno));
200  return;
201  }
202 
203 #if defined(__APPLE__)
204 #ifdef F_NOCACHE
205  fcntl(local_fd, F_NOCACHE, 1);
206 #endif
207 #elif defined(__sun__)
208  if (m_directio)
209  directio(local_fd, DIRECTIO_ON);
210 #endif
211 
212  //HT_DEBUGF("created file='%s' fd=%d local_fd=%d", fname, fd, local_fd);
213 
214  HT_INFOF("create( %s ) = %d (local=%d)", fname, (int)fd, local_fd);
215 
216  {
217  struct sockaddr_in addr;
218  OpenFileDataLocalPtr fdata(new OpenFileDataLocal(fname, local_fd, O_WRONLY));
219 
220  cb->get_address(addr);
221 
222  m_open_file_map.create(fd, addr, fdata);
223 
224  cb->response(fd);
225  }
226 }
227 
228 
229 void LocalBroker::close(ResponseCallback *cb, uint32_t fd) {
230  int error;
231  HT_DEBUGF("close fd=%d", fd);
232  m_open_file_map.remove(fd);
233  if ((error = cb->response_ok()) != Error::OK)
234  HT_ERRORF("Problem sending response for close(%u) - %s", (unsigned)fd, Error::get_text(error));
235 }
236 
237 
238 void LocalBroker::read(Response::Callback::Read *cb, uint32_t fd, uint32_t amount) {
239  OpenFileDataLocalPtr fdata;
240  ssize_t nread;
241  uint64_t offset;
242  int error;
243 
244  StaticBuffer buf((size_t)amount, (size_t)HT_DIRECT_IO_ALIGNMENT);
245 
246  HT_DEBUGF("read fd=%d amount=%d", fd, amount);
247 
248  if (!m_open_file_map.get(fd, fdata)) {
249  char errbuf[32];
250  sprintf(errbuf, "%d", fd);
252  HT_ERRORF("bad file handle: %d", fd);
253  m_metrics_handler->increment_error_count();
254  return;
255  }
256 
257  if ((offset = (uint64_t)lseek(fdata->fd, 0, SEEK_CUR)) == (uint64_t)-1) {
258  int error = errno;
259  report_error(cb);
260  if (error != EINVAL)
261  m_status_manager.set_read_error(error);
262  HT_ERRORF("lseek failed: fd=%d offset=0 SEEK_CUR - %s", fdata->fd,
263  strerror(errno));
264  return;
265  }
266 
267  if ((nread = FileUtils::read(fdata->fd, buf.base, amount)) == -1) {
268  int error = errno;
269  report_error(cb);
270  m_status_manager.set_read_error(error);
271  HT_ERRORF("read failed: fd=%d offset=%llu amount=%d - %s",
272  fdata->fd, (Llu)offset, amount, strerror(errno));
273  return;
274  }
275 
276  buf.size = nread;
277  m_metrics_handler->add_bytes_read(buf.size);
278 
279  m_status_manager.clear_status();
280 
281  if ((error = cb->response(offset, buf)) != Error::OK)
282  HT_ERRORF("Problem sending response for read(%u, %u) - %s",
283  (unsigned)fd, (unsigned)amount, Error::get_text(error));
284 
285 }
286 
287 
289  uint32_t amount, const void *data, Filesystem::Flags flags) {
290  OpenFileDataLocalPtr fdata;
291  ssize_t nwritten;
292  uint64_t offset;
293  int error;
294 
295  HT_DEBUG_OUT << "append fd=" << fd << " amount=" << amount << " data='"
296  << format_bytes(20, data, amount) << " flags="
297  << static_cast<uint8_t>(flags) << HT_END;
298 
299  if (!m_open_file_map.get(fd, fdata)) {
300  char errbuf[32];
301  sprintf(errbuf, "%d", fd);
303  m_metrics_handler->increment_error_count();
304  return;
305  }
306 
307  if ((offset = (uint64_t)lseek(fdata->fd, 0, SEEK_CUR)) == (uint64_t)-1) {
308  int error = errno;
309  report_error(cb);
310  if (error != EINVAL)
311  m_status_manager.set_write_error(error);
312  HT_ERRORF("lseek failed: fd=%d offset=0 SEEK_CUR - %s", fdata->fd,
313  strerror(errno));
314  return;
315  }
316 
317  if ((nwritten = FileUtils::write(fdata->fd, data, amount)) == -1) {
318  int error = errno;
319  report_error(cb);
320  m_status_manager.set_write_error(error);
321  HT_ERRORF("write failed: fd=%d offset=%llu amount=%d data=%p- %s",
322  fdata->fd, (Llu)offset, amount, data, strerror(errno));
323  return;
324  }
325 
326  if (flags == Filesystem::Flags::FLUSH || flags == Filesystem::Flags::SYNC) {
327  int64_t start_time = get_ts64();
328  if (fsync(fdata->fd) != 0) {
329  int error = errno;
330  report_error(cb);
331  m_status_manager.set_write_error(error);
332  HT_ERRORF("flush failed: fd=%d - %s", fdata->fd, strerror(errno));
333  return;
334  }
335  m_metrics_handler->add_sync(get_ts64() - start_time);
336  }
337 
338  m_metrics_handler->add_bytes_written(nwritten);
339  m_status_manager.clear_status();
340 
341  if ((error = cb->response(offset, nwritten)) != Error::OK)
342  HT_ERRORF("Problem sending response for append(%u, localfd=%u, %u) - %s",
343  (unsigned)fd, (unsigned)fdata->fd, (unsigned)amount, Error::get_text(error));
344 
345 }
346 
347 
348 void LocalBroker::seek(ResponseCallback *cb, uint32_t fd, uint64_t offset) {
349  OpenFileDataLocalPtr fdata;
350  int error;
351 
352  HT_DEBUGF("seek fd=%lu offset=%llu", (Lu)fd, (Llu)offset);
353 
354  if (!m_open_file_map.get(fd, fdata)) {
355  char errbuf[32];
356  sprintf(errbuf, "%d", fd);
358  m_metrics_handler->increment_error_count();
359  return;
360  }
361 
362  if ((offset = (uint64_t)lseek(fdata->fd, offset, SEEK_SET)) == (uint64_t)-1) {
363  report_error(cb);
364  HT_ERRORF("lseek failed: fd=%d offset=%llu - %s", fdata->fd, (Llu)offset,
365  strerror(errno));
366  return;
367  }
368 
369  if ((error = cb->response_ok()) != Error::OK)
370  HT_ERRORF("Problem sending response for seek(%u, %llu) - %s",
371  (unsigned)fd, (Llu)offset, Error::get_text(error));
372 
373 }
374 
375 
376 void LocalBroker::remove(ResponseCallback *cb, const char *fname) {
377  String abspath;
378  int error;
379 
380  HT_INFOF("remove file='%s'", fname);
381 
382  if (fname[0] == '/')
383  abspath = m_rootdir + fname;
384  else
385  abspath = m_rootdir + "/" + fname;
386 
387  if (m_no_removal) {
388  String deleted_file = abspath + ".deleted";
389  if (!FileUtils::rename(abspath, deleted_file)) {
390  report_error(cb);
391  return;
392  }
393  }
394  else {
395  if (unlink(abspath.c_str()) == -1) {
396  report_error(cb);
397  HT_ERRORF("unlink failed: file='%s' - %s", abspath.c_str(),
398  strerror(errno));
399  return;
400  }
401  }
402 
403  if ((error = cb->response_ok()) != Error::OK)
404  HT_ERRORF("Problem sending response for remove(%s) - %s",
405  fname, Error::get_text(error));
406 }
407 
408 
410  bool accurate) {
411  String abspath;
412  uint64_t length;
413  int error;
414 
415  HT_DEBUGF("length file='%s' (accurate=%s)", fname,
416  accurate ? "true" : "false");
417 
418  if (fname[0] == '/')
419  abspath = m_rootdir + fname;
420  else
421  abspath = m_rootdir + "/" + fname;
422 
423  if ((length = FileUtils::length(abspath)) == (uint64_t)-1) {
424  report_error(cb);
425  HT_ERRORF("length (stat) failed: file='%s' - %s", abspath.c_str(),
426  strerror(errno));
427  return;
428  }
429 
430  if ((error = cb->response(length)) != Error::OK)
431  HT_ERRORF("Problem sending response (%llu) for length(%s) - %s",
432  (Llu)length, fname, Error::get_text(error));
433 }
434 
435 
436 void
437 LocalBroker::pread(Response::Callback::Read *cb, uint32_t fd, uint64_t offset,
438  uint32_t amount, bool) {
439  OpenFileDataLocalPtr fdata;
440  ssize_t nread;
441  int error;
442 
443  HT_DEBUGF("pread fd=%d offset=%llu amount=%d", fd, (Llu)offset, amount);
444 
445  StaticBuffer buf((size_t)amount, (size_t)HT_DIRECT_IO_ALIGNMENT);
446 
447  if (!m_open_file_map.get(fd, fdata)) {
448  char errbuf[32];
449  sprintf(errbuf, "%d", fd);
451  m_metrics_handler->increment_error_count();
452  return;
453  }
454 
455  nread = FileUtils::pread(fdata->fd, buf.base, buf.aligned_size(), (off_t)offset);
456  if (nread != (ssize_t)buf.aligned_size()) {
457  int error = errno;
458  report_error(cb);
459  m_status_manager.set_read_error(error);
460  HT_ERRORF("pread failed: fd=%d amount=%d aligned_size=%d offset=%llu - %s",
461  fdata->fd, (int)amount, (int)buf.aligned_size(), (Llu)offset,
462  strerror(errno));
463  return;
464  }
465 
466  m_metrics_handler->add_bytes_read(nread);
467  m_status_manager.clear_status();
468 
469  if ((error = cb->response(offset, buf)) != Error::OK)
470  HT_ERRORF("Problem sending response for pread(%u, %llu, %u) - %s",
471  (unsigned)fd, (Llu)offset, (unsigned)amount, Error::get_text(error));
472 }
473 
474 
475 void LocalBroker::mkdirs(ResponseCallback *cb, const char *dname) {
476  String absdir;
477  int error;
478 
479  HT_DEBUGF("mkdirs dir='%s'", dname);
480 
481  if (dname[0] == '/')
482  absdir = m_rootdir + dname;
483  else
484  absdir = m_rootdir + "/" + dname;
485 
486  if (!FileUtils::mkdirs(absdir)) {
487  report_error(cb);
488  HT_ERRORF("mkdirs failed: dname='%s' - %s", absdir.c_str(),
489  strerror(errno));
490  return;
491  }
492 
493  if ((error = cb->response_ok()) != Error::OK)
494  HT_ERRORF("Problem sending response for mkdirs(%s) - %s",
495  dname, Error::get_text(error));
496 }
497 
498 
499 void LocalBroker::rmdir(ResponseCallback *cb, const char *dname) {
500  String absdir;
501  String cmd_str;
502  int error;
503 
504  if (m_verbose)
505  HT_INFOF("rmdir dir='%s'", dname);
506 
507  if (dname[0] == '/')
508  absdir = m_rootdir + dname;
509  else
510  absdir = m_rootdir + "/" + dname;
511 
512  if (FileUtils::exists(absdir)) {
513  if (m_no_removal) {
514  String deleted_file = absdir + ".deleted";
515  if (!FileUtils::rename(absdir, deleted_file)) {
516  report_error(cb);
517  return;
518  }
519  }
520  else {
521  cmd_str = (String)"/bin/rm -rf " + absdir;
522  if (system(cmd_str.c_str()) != 0) {
523  HT_ERRORF("%s failed.", cmd_str.c_str());
524  m_metrics_handler->increment_error_count();
525  cb->error(Error::FSBROKER_IO_ERROR, cmd_str);
526  return;
527  }
528  }
529  }
530 
531 #if 0
532  if (rmdir(absdir.c_str()) != 0) {
533  report_error(cb);
534  HT_ERRORF("rmdir failed: dname='%s' - %s", absdir.c_str(), strerror(errno));
535  return;
536  }
537 #endif
538 
539  if ((error = cb->response_ok()) != Error::OK)
540  HT_ERRORF("Problem sending response for mkdirs(%s) - %s",
541  dname, Error::get_text(error));
542 
543 }
544 
545 void LocalBroker::readdir(Response::Callback::Readdir *cb, const char *dname) {
546  std::vector<Filesystem::Dirent> listing;
547  Filesystem::Dirent entry;
548  String absdir;
549 
550  HT_DEBUGF("Readdir dir='%s'", dname);
551 
552  if (dname[0] == '/')
553  absdir = m_rootdir + dname;
554  else
555  absdir = m_rootdir + "/" + dname;
556 
557  DIR *dirp = opendir(absdir.c_str());
558  if (dirp == 0) {
559  report_error(cb);
560  HT_ERRORF("opendir('%s') failed - %s", absdir.c_str(), strerror(errno));
561  return;
562  }
563 
564  struct dirent *dp = (struct dirent *)new uint8_t [sizeof(struct dirent)+1025];
565  struct dirent *result;
566 
567  if (readdir_r(dirp, dp, &result) != 0) {
568  report_error(cb);
569  HT_ERRORF("readdir('%s') failed - %s", absdir.c_str(), strerror(errno));
570  (void)closedir(dirp);
571  delete [] (uint8_t *)dp;
572  return;
573  }
574 
575  String full_entry_path;
576  struct stat statbuf;
577  while (result != 0) {
578 
579  if (result->d_name[0] != '.' && result->d_name[0] != 0) {
580  if (m_no_removal) {
581  size_t len = strlen(result->d_name);
582  if (len <= 8 || strcmp(&result->d_name[len-8], ".deleted")) {
583  entry.name.clear();
584  entry.name.append(result->d_name);
585  entry.is_dir = result->d_type == DT_DIR;
586  full_entry_path.clear();
587  full_entry_path.append(absdir);
588  full_entry_path.append("/");
589  full_entry_path.append(entry.name);
590  if (stat(full_entry_path.c_str(), &statbuf) == -1) {
591  if (errno != ENOENT) {
592  report_error(cb);
593  HT_ERRORF("readdir('%s') failed - %s", absdir.c_str(), strerror(errno));
594  delete [] (uint8_t *)dp;
595  return;
596  }
597  }
598  else {
599  entry.length = (uint64_t)statbuf.st_size;
600  entry.last_modification_time = statbuf.st_mtime;
601  listing.push_back(entry);
602  }
603  }
604  }
605  else {
606  entry.name.clear();
607  entry.name.append(result->d_name);
608  entry.is_dir = result->d_type == DT_DIR;
609  full_entry_path.clear();
610  full_entry_path.append(absdir);
611  full_entry_path.append("/");
612  full_entry_path.append(entry.name);
613  if (stat(full_entry_path.c_str(), &statbuf) == -1) {
614  report_error(cb);
615  HT_ERRORF("readdir('%s') failed - %s", absdir.c_str(), strerror(errno));
616  delete [] (uint8_t *)dp;
617  return;
618  }
619  entry.length = (uint64_t)statbuf.st_size;
620  entry.last_modification_time = statbuf.st_mtime;
621  listing.push_back(entry);
622  }
623  //HT_INFOF("readdir Adding listing '%s'", result->d_name);
624  }
625 
626  if (readdir_r(dirp, dp, &result) != 0) {
627  report_error(cb);
628  HT_ERRORF("readdir('%s') failed - %s", absdir.c_str(), strerror(errno));
629  delete [] (uint8_t *)dp;
630  return;
631  }
632  }
633  (void)closedir(dirp);
634 
635  delete [] (uint8_t *)dp;
636 
637  HT_DEBUGF("Sending back %d listings", (int)listing.size());
638 
639  cb->response(listing);
640 }
641 
642 void LocalBroker::flush(ResponseCallback *cb, uint32_t fd) {
643  this->sync(cb, fd);
644 }
645 
646 void LocalBroker::sync(ResponseCallback *cb, uint32_t fd) {
647  OpenFileDataLocalPtr fdata;
648 
649  HT_DEBUGF("sync fd=%d", fd);
650 
651  if (!m_open_file_map.get(fd, fdata)) {
652  char errbuf[32];
653  sprintf(errbuf, "%d", fd);
655  return;
656  }
657 
658  int64_t start_time = get_ts64();
659  if (fsync(fdata->fd) != 0) {
660  int error = errno;
661  report_error(cb);
662  m_status_manager.set_write_error(error);
663  HT_ERRORF("sync failed: fd=%d - %s", fdata->fd, strerror(errno));
664  return;
665  }
666 
667  m_metrics_handler->add_sync(get_ts64() - start_time);
668  m_status_manager.clear_status();
669 
670  cb->response_ok();
671 }
672 
673 
675  cb->response(m_status_manager.get());
676 }
677 
678 
680  m_open_file_map.remove_all();
681  cb->response_ok();
682  this_thread::sleep_for(chrono::milliseconds(2000));
683 }
684 
685 
686 void LocalBroker::exists(Response::Callback::Exists *cb, const char *fname) {
687  String abspath;
688 
689  HT_DEBUGF("exists file='%s'", fname);
690 
691  if (fname[0] == '/')
692  abspath = m_rootdir + fname;
693  else
694  abspath = m_rootdir + "/" + fname;
695 
696  cb->response(FileUtils::exists(abspath));
697 }
698 
699 
700 void
701 LocalBroker::rename(ResponseCallback *cb, const char *src, const char *dst) {
702  HT_INFOF("rename %s -> %s", src, dst);
703 
704  String asrc =
705  format("%s%s%s", m_rootdir.c_str(), *src == '/' ? "" : "/", src);
706  String adst =
707  format("%s%s%s", m_rootdir.c_str(), *dst == '/' ? "" : "/", dst);
708 
709  if (std::rename(asrc.c_str(), adst.c_str()) != 0) {
710  report_error(cb);
711  return;
712  }
713  cb->response_ok();
714 }
715 
716 void
718  StaticBuffer &serialized_parameters) {
719  HT_ERRORF("debug command %d not implemented.", command);
720  cb->error(Error::NOT_IMPLEMENTED, format("Unsupported debug command - %d",
721  command));
722 }
723 
724 
725 
727  char errbuf[128];
728  errbuf[0] = 0;
729 
730  m_metrics_handler->increment_error_count();
731 
732  strerror_r(errno, errbuf, 128);
733 
734  if (errno == ENOTDIR || errno == ENAMETOOLONG || errno == ENOENT)
735  cb->error(Error::FSBROKER_BAD_FILENAME, errbuf);
736  else if (errno == EACCES || errno == EPERM)
738  else if (errno == EBADF)
740  else if (errno == EINVAL)
742  else
743  cb->error(Error::FSBROKER_IO_ERROR, errbuf);
744 }
A memory buffer of static size.
Definition: StaticBuffer.h:45
Retrieves system information (hardware, installation directory, etc)
int response(bool exists)
Sends response parameters back to client.
Definition: Exists.cc:40
virtual void shutdown(ResponseCallback *cb)
Gracefully shutdown broker, closeing open files.
Definition: LocalBroker.cc:679
void get_address(struct sockaddr_in &addr)
Gets the remote address of the requesting client.
static atomic< int > ms_next_fd
Definition: LocalBroker.h:98
Application handler for append function.
Definition: Append.h:45
virtual void read(Response::Callback::Read *cb, uint32_t fd, uint32_t amount)
Read data from an open file.
Definition: LocalBroker.cc:238
Abstract base class for a filesystem.
static bool read(const String &fname, String &contents)
Reads a whole file into a String.
Definition: FileUtils.cc:59
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
Compatibility class for boost::filesystem::path.
virtual void create(Response::Callback::Open *cb, const char *fname, uint32_t flags, int32_t bufsz, int16_t replication, int64_t blksz)
Open a file, and create it if it doesn't exist, optionally overwriting the contents.
Definition: LocalBroker.cc:167
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
virtual void mkdirs(ResponseCallback *cb, const char *dname)
Make a directory hierarcy, If the parent dirs are not, present, they are also created.
Definition: LocalBroker.cc:475
static off_t length(const String &fname)
Returns the size of a file (-1 on error)
Definition: FileUtils.cc:458
virtual int response_ok()
Sends a a simple success response back to the client which is just the 4-byte error code Error::OK...
int response(int32_t fd)
Sends response parameters back to client.
Definition: Open.cc:40
Flags
Enumeration type for append flags.
Definition: Filesystem.h:76
virtual void remove(ResponseCallback *cb, const char *fname)
Remove a file or directory.
Definition: LocalBroker.cc:376
long long unsigned int Llu
Shortcut for printf formats.
Definition: String.h:50
Application handler for exists function.
Definition: Exists.h:45
static ssize_t write(const String &fname, const std::string &contents)
Writes a String buffer to a file; the file is overwritten if it already exists.
Definition: FileUtils.cc:124
File system broker definitions.
Definition: CephBroker.h:38
static bool exists(const String &fname)
Checks if a file or directory exists.
Definition: FileUtils.cc:420
virtual void readdir(Response::Callback::Readdir *cb, const char *dname)
Read a directory's contents.
Definition: LocalBroker.cc:545
STL namespace.
static bool mkdirs(const String &dirname)
Creates a directory (with all parent directories, if required)
Definition: FileUtils.cc:366
time_t last_modification_time
Last modification time.
Definition: Filesystem.h:100
virtual void pread(Response::Callback::Read *cb, uint32_t fd, uint64_t offset, uint32_t amount, bool verify_checksum)
Read from file at position.
Definition: LocalBroker.cc:437
String format_bytes(size_t n, const void *buf, size_t len, const char *trailer)
Return first n bytes of buffer with an optional trailer if the size of the buffer exceeds n...
Definition: String.cc:103
static ssize_t pread(int fd, void *vptr, size_t n, off_t offset)
Reads positional data from a file descriptor into a buffer.
Definition: FileUtils.cc:97
virtual void status(Response::Callback::Status *cb)
Check status of FSBroker.
Definition: LocalBroker.cc:674
virtual void rmdir(ResponseCallback *cb, const char *dname)
Remove a directory.
Definition: LocalBroker.cc:499
virtual void flush(ResponseCallback *cb, uint32_t fd)
Flush data that has been written.
Definition: LocalBroker.cc:642
uint64_t length
Length of file.
Definition: Filesystem.h:98
virtual void rename(ResponseCallback *cb, const char *src, const char *dst)
Rename a file from src to dst.
Definition: LocalBroker.cc:701
bool is_dir
Flag indicating if entry id a directory.
Definition: Filesystem.h:102
Application handler for length function.
Definition: Length.h:45
Compatibility class for boost::filesystem::path.
Definition: Path.h:45
virtual void debug(ResponseCallback *, int32_t command, StaticBuffer &serialized_parameters)
Debug command.
Definition: LocalBroker.cc:717
File system utility functions.
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
static const OsInfo & os_info()
Retrieves updated Operating system information (see SystemInfo.h)
Definition: SystemInfo.cc:347
Compatibility Macros for C/C++.
LocalBroker(PropertiesPtr &props)
Definition: LocalBroker.cc:62
#define HT_END
Definition: Logger.h:220
int response(uint64_t offset, StaticBuffer &buffer)
Sends response parameters back to client.
Definition: Read.cc:40
virtual void close(ResponseCallback *cb, uint32_t fd)
Close open file.
Definition: LocalBroker.cc:229
const int version_minor
Definition: Version.cc:32
This class is used to generate and deliver standard responses back to a client.
virtual void open(Response::Callback::Open *cb, const char *fname, uint32_t flags, uint32_t bufsz)
Open a file and pass the fd to the callback on success.
Definition: LocalBroker.cc:111
int response(std::vector< Filesystem::Dirent > &listing)
Sends response parameters back to client.
Definition: Readdir.cc:41
Application handler for readdir function.
Definition: Readdir.h:48
Hypertable definitions
#define HT_DEBUGF(msg,...)
Definition: Logger.h:260
long long int Lld
Shortcut for printf formats.
Definition: String.h:53
Application handler for open function.
Definition: Open.h:45
Application handler for read function.
Definition: Read.h:47
virtual int error(int error, const String &msg)
Sends a standard error response back to the client.
#define HT_INFOF(msg,...)
Definition: Logger.h:272
String name
File or directory name.
Definition: Filesystem.h:96
const int version_major
Definition: Version.cc:31
virtual void sync(ResponseCallback *cb, uint32_t fd)
Sync out data that has been written.
Definition: LocalBroker.cc:646
Declarations for ReactorFactory.
Application handler for open function.
Definition: Status.h:50
int response(Hypertable::Status &status)
Sends response parameters back to client.
Definition: Status.cc:40
A String class based on std::string.
virtual void report_error(ResponseCallback *cb)
Definition: LocalBroker.cc:726
long unsigned int Lu
Shortcut for printf formats.
Definition: String.h:47
#define HT_ERRORF(msg,...)
Definition: Logger.h:300
int response(uint64_t offset, uint32_t amount)
Sends response parameters back to client.
Definition: Append.cc:40
static bool rename(const String &oldpath, const String &newpath)
Renames a file or directory.
Definition: FileUtils.cc:438
System information and statistics based on libsigar.
virtual void append(Response::Callback::Append *cb, uint32_t fd, uint32_t amount, const void *data, Filesystem::Flags flags)
Append data to open file.
Definition: LocalBroker.cc:288
int response(uint64_t length)
Sends response parameters back to client.
Definition: Length.cc:40
virtual void seek(ResponseCallback *cb, uint32_t fd, uint64_t offset)
Seek open file.
Definition: LocalBroker.cc:348
#define HT_DEBUG_OUT
Definition: Logger.h:261
int64_t get_ts64()
Returns the current time in nanoseconds as a 64bit number.
Definition: Time.cc:40
#define HT_DIRECT_IO_ALIGNMENT
Definition: Filesystem.h:49
virtual void length(Response::Callback::Length *cb, const char *fname, bool accurate=true)
Get length of file.
Definition: LocalBroker.cc:409
virtual void exists(Response::Callback::Exists *cb, const char *fname)
Check for the existence of a file.
Definition: LocalBroker.cc:686